History

TimeSeriesPlatformLibrary: (1) Fixed issue with SignalReference parser, (2) converted tabs to spaces, (3) tested 64-bit compilation

J. Ritchie Carroll committed 8 years ago

Commit 3dfa6731 parent dab518924 files · +3167 −3043Browse files

Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Common/Convert.cpp (1 of 24 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Common/Convert.cpp+111−111
@@ -37,143 +37,143 @@ using namespace GSF::TimeSeries; · 36 unmodified lines
3737
3838 void GSF::TimeSeries::GetUnixTime(const int64_t ticks, time_t& unixSOC, int16_t& milliseconds)
3939 {
40− // Unix dates are measured as the number of seconds since 1/1/1970
41− const int64_t BaseTimeOffset = 621355968000000000L;
40+ // Unix dates are measured as the number of seconds since 1/1/1970
41+ const int64_t BaseTimeOffset = 621355968000000000L;
4242
43− unixSOC = static_cast<time_t>((ticks - BaseTimeOffset) / 10000000);
44− milliseconds = static_cast<int16_t>(ticks / 10000 % 1000);
43+ unixSOC = static_cast<time_t>((ticks - BaseTimeOffset) / 10000000);
44+ milliseconds = static_cast<int16_t>(ticks / 10000 % 1000);
4545 }
4646
4747 size_t GSF::TimeSeries::TicksToString(char* ptr, size_t maxsize, string format, int64_t ticks)
4848 {
49− time_t fromSeconds;
50− int16_t milliseconds;
51−
52− GetUnixTime(ticks, fromSeconds, milliseconds);
53−
54− stringstream formatStream;
55− size_t formatIndex = 0;
56−
57− while (formatIndex < format.size())
58− {
59− char c = format[formatIndex];
60− ++formatIndex;
61−
62− if (c != '%')
63− {
64− // Not a format specifier
65− formatStream << c;
66− continue;
67− }
68−
69− // Check for %f and %t format specifiers and handle them
70− // accordingly. All other specifiers get forwarded to strftime
71− c = format[formatIndex];
72− ++formatIndex;
73−
74− switch (c)
75− {
76− case 'f':
77− {
78− stringstream temp;
79− temp << setw(3) << setfill('0') << milliseconds;
80− formatStream << temp.str();
81− break;
82− }
83−
84− case 't':
85− formatStream << ticks;
86− break;
87−
88− default:
89− formatStream << '%' << c;
90− break;
91− }
92− }
93−
94− struct tm timeinfo;
95− gmtime_s(&timeinfo, &fromSeconds);
96−
97− return strftime(ptr, maxsize, formatStream.str().data(), &timeinfo);
49+ time_t fromSeconds;
50+ int16_t milliseconds;
51+
52+ GetUnixTime(ticks, fromSeconds, milliseconds);
53+
54+ stringstream formatStream;
55+ size_t formatIndex = 0;
56+
57+ while (formatIndex < format.size())
58+ {
59+ char c = format[formatIndex];
60+ ++formatIndex;
61+
62+ if (c != '%')
63+ {
64+ // Not a format specifier
65+ formatStream << c;
66+ continue;
67+ }
68+
69+ // Check for %f and %t format specifiers and handle them
70+ // accordingly. All other specifiers get forwarded to strftime
71+ c = format[formatIndex];
72+ ++formatIndex;
73+
74+ switch (c)
75+ {
76+ case 'f':
77+ {
78+ stringstream temp;
79+ temp << setw(3) << setfill('0') << milliseconds;
80+ formatStream << temp.str();
81+ break;
82+ }
83+
84+ case 't':
85+ formatStream << ticks;
86+ break;
87+
88+ default:
89+ formatStream << '%' << c;
90+ break;
91+ }
92+ }
93+
94+ struct tm timeinfo;
95+ gmtime_s(&timeinfo, &fromSeconds);
96+
97+ return strftime(ptr, maxsize, formatStream.str().data(), &timeinfo);
9898 }
9999
100100 template <class T>
101101 string GSF::TimeSeries::ToString(const T& obj)
102102 {
103− stringstream stream;
104− stream << obj;
105− return stream.str();
103+ stringstream stream;
104+ stream << obj;
105+ return stream.str();
106106 }
107107
108108 Guid GSF::TimeSeries::ToGuid(const uint8_t* data, bool swapBytes)
109109 {
110− Guid id;
111− uint8_t swappedBytes[16];
112− uint8_t* encodedBytes;
113−
114− // Check if bytes need to be decoded in reverse order
115− if (swapBytes)
116− {
117− uint8_t copy[8];
118−
119− for (size_t i = 0; i < 16; i++)
120− {
121− swappedBytes[i] = data[15 - i];
122−
123− if (i < 8)
124− copy[i] = swappedBytes[i];
125− }
126−
127− // Convert Microsoft encoding to RFC
128− swappedBytes[3] = copy[0];
129− swappedBytes[2] = copy[1];
130− swappedBytes[1] = copy[2];
131− swappedBytes[0] = copy[3];
132−
133− swappedBytes[4] = copy[5];
134− swappedBytes[5] = copy[4];
135−
136− swappedBytes[6] = copy[7];
137− swappedBytes[7] = copy[6];
138−
139− encodedBytes = swappedBytes;
140− }
141− else
142− {
143− encodedBytes = const_cast<uint8_t*>(data);
144− }
145−
146− for (Guid::iterator iter = id.begin(); iter != id.end(); ++iter, ++encodedBytes)
147− *iter = static_cast<Guid::value_type>(*encodedBytes);
148−
149− return id;
110+ Guid id;
111+ uint8_t swappedBytes[16];
112+ uint8_t* encodedBytes;
113+
114+ // Check if bytes need to be decoded in reverse order
115+ if (swapBytes)
116+ {
117+ uint8_t copy[8];
118+
119+ for (size_t i = 0; i < 16; i++)
120+ {
121+ swappedBytes[i] = data[15 - i];
122+
123+ if (i < 8)
124+ copy[i] = swappedBytes[i];
125+ }
126+
127+ // Convert Microsoft encoding to RFC
128+ swappedBytes[3] = copy[0];
129+ swappedBytes[2] = copy[1];
130+ swappedBytes[1] = copy[2];
131+ swappedBytes[0] = copy[3];
132+
133+ swappedBytes[4] = copy[5];
134+ swappedBytes[5] = copy[4];
135+
136+ swappedBytes[6] = copy[7];
137+ swappedBytes[7] = copy[6];
138+
139+ encodedBytes = swappedBytes;
140+ }
141+ else
142+ {
143+ encodedBytes = const_cast<uint8_t*>(data);
144+ }
145+
146+ for (Guid::iterator iter = id.begin(); iter != id.end(); ++iter, ++encodedBytes)
147+ *iter = static_cast<Guid::value_type>(*encodedBytes);
148+
149+ return id;
150150 }
151151
152152 Guid GSF::TimeSeries::ToGuid(const char* data)
153153 {
154− const string_generator generator;
155− return generator(data);
154+ const string_generator generator;
155+ return generator(data);
156156 }
157157
158158 const char* GSF::TimeSeries::Coalesce(const char* data, const char* nonEmptyValue)
159159 {
160− if (data == nullptr)
161− return nonEmptyValue;
160+ if (data == nullptr)
161+ return nonEmptyValue;
162162
163− if (strlen(data) == 0)
164− return nonEmptyValue;
163+ if (strlen(data) == 0)
164+ return nonEmptyValue;
165165
166− return data;
166+ return data;
167167 }
168168
169169 time_t GSF::TimeSeries::ParseXMLTimestamp(const char* time)
170170 {
171− istringstream in { time };
172− sys_seconds timestamp;
173−
174− // Parse an XML formatted timestamp string, e.g.: 2018-03-14T19:23:11.665-04:00,
175− // using the Hinnant date library: https://github.com/HowardHinnant/date
176− in >> parse("%Y-%m-%dT%T%z", timestamp);
177−
178− return system_clock::to_time_t(timestamp);
171+ istringstream in { time };
172+ sys_seconds timestamp;
173+
174+ // Parse an XML formatted timestamp string, e.g.: 2018-03-14T19:23:11.665-04:00,
175+ // using the Hinnant date library: https://github.com/HowardHinnant/date
176+ in >> parse("%Y-%m-%dT%T%z", timestamp);
177+
178+ return system_clock::to_time_t(timestamp);
179179 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t