Skip to content

Commit 37473aa

Browse files
Feature replace cmarkup with tinyxml2 (#109)
* tests passing * Extracted serialization from rtprotocol * Use a separate serializer for each function to enable gradual replacement * Extended ISettingsSerializer interface, restored Deserialize6DOFSettings * Removed todo * Build examples * Renamed parameters * Renamed parameters * renamed parameters * mini reformat for readability * Fixed minor/major mixup * Adding 'Tinyxml2Serializer' shell, commented out CMarkup code within each function. * Properly include tinyxml2 * [Feature Branch] - CMarkup --> Tinyxml2 : SetSkeletonSettings() (#70) * Changed to tinyxml2 in 'SetSkeletonSettings', as well as dependant function. * Add else-statement to include 'LowerBound' and 'UpperBound' when 'Constraint' is missing. * Remove unnecessary explicit string-construction. * Removed pointers from functions, replaced with references. * [Feature Branch] - CMarkup --> Tinyxml2 : Set6DOFBodySettings() (#71) * Changed 'Set6DOFBodySettings' to use tinyxml2. * Output is slightly different still. Saving progress. * Test now passes. Removed a newline at the start of the test data set for 6DOF. Not sure if it needs to be there or not. * Revert the data since the newline doesn't seem to matter. * Removed unnecessary explicit string-construction, renamed from 'doc' to 'oXML'. * [Feature Branch] - CMarkup --> Tinyxml2 : SetForceSettings() (#72) * Updated 'SetForceSettings' function for Tinyxml2 serializer. * Change pointers to references where applicable in new code. * Change pointers to references where applicable in new code. * Fix merge issues. * Changed namespace to qualisys_cpp_sdk * [Feature Branch] - CMarkup --> Tinyxml2 : SetImageSettings() (#73) * Saving progress. * Added 'SetForceSettings' function. * Remove unnecessary explicit string-construction. --------- Co-authored-by: johannes.gotlen <[email protected]> * [Feature Branch] - CMarkup --> Tinyxml2 : SetGeneralSettings() (#75) * Added 'SetGeneralSettings' function. * Reverted 'AddXMLElementBool' functions to contain default-specified texts for 'True' and 'False' alternatives, since there are commented out functions that need to specify these texts. --------- Co-authored-by: johannes.gotlen <[email protected]> * [Feature Branch] - CMarkup --> Tinyxml2 : DeserializeEyeTrackerSettings() (#74) * Implemented CTinyxml2Deserializer::DeserializeEyeTrackerSettings, CTinyxml2Deserializer::ReadXmlBool * formatted else * removed extra include * use static_cast --------- Co-authored-by: Oliver Glandberger <[email protected]> * [Feature Branch] - CMarkup --> Tinyxml2 : DeserializeGazeVectorSettings() (#76) * Implemented CTinyxml2Deserializer::DeserializeEyeTrackerSettings, CTinyxml2Deserializer::ReadXmlBool * formatted else * removed extra include * use static_cast * Tests passing * [Feature Branch] - CMarkup --> Tinyxml2 : Deserialize6DOFSettings() (#77) * Implemented CTinyxml2Deserializer::DeserializeEyeTrackerSettings, CTinyxml2Deserializer::ReadXmlBool * formatted else * removed extra include * use static_cast * Tests passing * Tests passing * [Feature Branch] - CMarkup --> Tinyxml2 : Deserialize3DSettings() (#78) * Implemented CTinyxml2Deserializer::DeserializeEyeTrackerSettings, CTinyxml2Deserializer::ReadXmlBool * formatted else * removed extra include * use static_cast * Tests passing * Tests passing * Test passes * Deserialize general settings. Tests passing (#80) * DeserializeAnalogSettings, Tests Passing (#81) * Added initial refactor of 'SetExtTimestampSettings' function for tinyxml2. (#79) * Added initial refactor of 'SetExtTimeBaseSettings' function for tinyxml2. (#82) * Added initial refactor of 'SetCameraVideoSettings' function for tinyxml2. (#83) * Added initial refactor of 'SetCameraSyncOutSettings' function for tinyxml2. (#84) * [Feature Branch] - CMarkup --> Tinyxml2 : SetCameraSettings() (#85) * Initial push to change 'SetCameraSettngs' to use tinyxml2. * Remove unnecessary comment. * [Feature Branch] - CMarkup --> Tinyxml2 : SetCameraLensControlSettings() (#86) * Initial push to change 'SetCameraLensSettings' to use tinyxml2. * Remove unnecessary string. * Updated new 'AddXMLElementFloatWithTextAttribute', removed prefix letters, updated order of parameters, udpated pointers. * Initial push to change 'SetCameraAutoWhiteBalanceSettings' to use tinyxml2. (#87) * Initial push to change 'SetCameraAutoExposureSettings' to use tinyxml2. (#88) * [Feature Branch] - CMarkup --> Tinyxml2 : DeserializeForceSettings() (#89) * DeserializeForceSettings Incomplete testing * DeserializeForceSettings. New test data. Tests passing * Formatting change * Changed to range based for loops * Removed initialization loop * Added newline * Whitepsace * Formatting update * Deserialize image settings, tests passing (#90) * [Feature Branch] - Tinyxml2 : Integrate tinyxml2 Using Git Submodule (#91) * Removed './cmake/tinyxml2.cmake', added tinyxml2 as a submodule, updated relevant 'CMakeLists.txt' files accordingly. * Added 'branch = v10.0.0' to '.gitmodules'. * Updated 'README.md' to reflect now adding tinyxml2 via submodule. * Saving branch. * Initial fix that makes this project consumable by QTM. * Updating CMakeLists.txt. * Removed unnecessary spaces. * DeserializeSkeletonSettings, Tests passing (#92) * Tinyxml2 : DeserializeCalibrationSettings() * Split up Tinyxml2Serializer/Tinyxml2Deserializer * Fixed `sprintf` notices by changing to `sprintf_s` * Tinyxml2Deserializer: Removed private functions * Tinyxml2Deserializer: Renamed private variables * Tinyxml2Deserializer: Renamed private variables * Tinyxml2Deserializer: Removed some of the over-specialized helper functions (#95) * [Feature Branch] - Tinyxml2Deserializer: Extracted deserialization interface (#96) * extracted seralization interface * Fixup cmak file * Fixup. Removed extra endlines * [Feature Branch] - Refactor Naming Serializer (#97) * Started renaming variables in Tinyxml2Serializer. * Finished renaming. * Minor updates. * Remove the unnecessary comments, some minor changes. * In the middle of renaming many parameter and variable names. Code builds and tests pass. Saving progress. * Finished renaming in 'RTProtocol.h'. * Finished renaming parameters and variables in 'RTProtocol.cpp'. * Finished with 'Settings.h'. * Merged feature branch, fixed conflicts. * Additional minor changes. * Reverting Deserializer files. * Revert accidental change from x,y,z to x,x,x. * Removing 'e' from two local variables in 'SetCameraVideoSettingsTest'. * Reverted changes to 'Settings.h', 'RTProtocol.h', and test files. Also reverted changes that are not required right now in MarkupSerializer.cpp. * [Feature Branch] - Refactor Naming Deserializer (#98) * Started renaming variables in Tinyxml2Serializer. * Finished renaming. * Minor updates. * Remove the unnecessary comments, some minor changes. * In the middle of renaming many parameter and variable names. Code builds and tests pass. Saving progress. * Finished renaming in 'RTProtocol.h'. * Finished renaming parameters and variables in 'RTProtocol.cpp'. * Finished with 'Settings.h'. * Merged feature branch, fixed conflicts. * Additional minor changes. * Reverting Deserializer files. * Revert accidental change from x,y,z to x,x,x. * Removing 'e' from two local variables in 'SetCameraVideoSettingsTest'. * Reverted changes to 'Settings.h', 'RTProtocol.h', and test files. Also reverted changes that are not required right now in MarkupSerializer.cpp. * Refactoring Deserializer names, some small changes in RTProtocol.cpp and MarkupSerializer .h and .cpp. * Update some additional names. * Revert "[Feature Branch] - Refactor Naming Deserializer (#98)" (#99) This reverts commit dda77f1. * [Feature Branch] - Refactor Naming Deserializer (#100) * Started renaming variables in Tinyxml2Serializer. * Finished renaming. * Minor updates. * Remove the unnecessary comments, some minor changes. * In the middle of renaming many parameter and variable names. Code builds and tests pass. Saving progress. * Finished renaming in 'RTProtocol.h'. * Finished renaming parameters and variables in 'RTProtocol.cpp'. * Finished with 'Settings.h'. * Merged feature branch, fixed conflicts. * Additional minor changes. * Reverting Deserializer files. * Revert accidental change from x,y,z to x,x,x. * Removing 'e' from two local variables in 'SetCameraVideoSettingsTest'. * Reverted changes to 'Settings.h', 'RTProtocol.h', and test files. Also reverted changes that are not required right now in MarkupSerializer.cpp. * Refactoring Deserializer names, some small changes in RTProtocol.cpp and MarkupSerializer .h and .cpp. * Update some additional names. * Removing mingw_build folder. * [FeatureBranch] Tinyxml2 deserializer cleanup (#103) * ranged based for, narrowed scope of some variables * removed root element variables * Formatted document * Adjusted closing parenthesis * Hiked up parenthesis * Renamed formal parameters * Sorted includes * Line break after if block * [Feature Branch] - Refactor Into 'Serializer' Class (#102) * Checked out to previous commit. * Initial commit that extracts tinyxml2 dependency to 'Serializer.h' and 'Serializer.cpp'. * Fixed issues causing the projects to not build when opening the solution in Visual Studio. * Remove 'tinyxml2.h' from 'Serializer.h' and move it to 'Serializer.cpp'. * Revert to change that auto-reverted by Visual Studio. * Rename serialization files (#104) * Renamed files * Renamed files and removed leaking headers * Fixed dll export issue * Fixed vcxproj build errors * Renamed parameters * Renamed files * [FeatureBranch] Tinyxml2 cleanup (#105) * Removed settings structs from DeserializerAPI * Serializer wip * restored support for optional force plate corners * SetSettings6Dof * Fixed incorrect element creation of '2D' and '3D', removed commented out code. * Removing unused 'GeneralSettings' function from SerializerApi.h. * Removed 'SetExtTimeBaseSettings' from 'SerializerApi.h' and moved to 'SettingsSerializer.cpp'. * Removed 'SetExtTimestampSettings' from 'SerializerApi.h', moved to 'SettingsSerializer.cpp'. * Removed 'SetCameraVideoSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Removed 'SetCameraSyncOutSettings' from 'SerializerApi.h', moved to 'SettingsSerializer.cpp'. * Removed 'SetCameraLensControlSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Removed 'SetCameraAutoExposureSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Reformated creation of root elements. * Renamed deserializer function * Removed 'SetCameraAutoWhiteBalance' from 'SerializeApi', moved to 'SettingsSerializer'. * Removed 'SetImageSettings' from 'SerializerApi', moved to 'SettingsSerializer', * Removed 'SetForceSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Moved deserializer api TryRead.. functions into class scope * Renamed deserializer methods * Renamed deserializer api find element methods * Saving progress. * Simplified ChildElementRange * Share buffer * Fixup deserializer row/col itertor * Fixup Deserialize Calibration_Matrix * Started moving out 'SetSkeletonSettings' from 'SerializerApi' to 'SettingsSerializer'. It compiles but there are some diffs. * Fixed Marker/Weight skeleton serialization issue * Removed 'SetSkeletonSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Remove unused helper functions. * Removing unnecessary newlines. * Cleaned up SerializerApi.h * Cleaned up SerializerApi.h * Removed variable decimal count * Removed calls to std::to_string * Adding 'cstring' include to 'RTProtocol.cpp'. * Change to 'sprintf_s' variant. * Added 'algorithm' include to 'Settings.cpp'. * Updating to 'snprintf'. * Fixed use of overlapping buffer with snprintf --------- Co-authored-by: Oliver Glandberger <[email protected]> * [Feature Branch] - Removes (old) serialization library CMarkup (#107) * Removed alternate serialization library * Filter fixes * Removed "Serialize/Deserializer" from project filter * [Feature Branch] - Fix Compiler Issues (mingw, GNU, Linux, Windows, etc.) (#108) * Removed settings structs from DeserializerAPI * Serializer wip * restored support for optional force plate corners * SetSettings6Dof * Fixed incorrect element creation of '2D' and '3D', removed commented out code. * Removing unused 'GeneralSettings' function from SerializerApi.h. * Removed 'SetExtTimeBaseSettings' from 'SerializerApi.h' and moved to 'SettingsSerializer.cpp'. * Removed 'SetExtTimestampSettings' from 'SerializerApi.h', moved to 'SettingsSerializer.cpp'. * Removed 'SetCameraVideoSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Removed 'SetCameraSyncOutSettings' from 'SerializerApi.h', moved to 'SettingsSerializer.cpp'. * Removed 'SetCameraLensControlSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Removed 'SetCameraAutoExposureSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Reformated creation of root elements. * Renamed deserializer function * Removed 'SetCameraAutoWhiteBalance' from 'SerializeApi', moved to 'SettingsSerializer'. * Removed 'SetImageSettings' from 'SerializerApi', moved to 'SettingsSerializer', * Removed 'SetForceSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Moved deserializer api TryRead.. functions into class scope * Renamed deserializer methods * Renamed deserializer api find element methods * Saving progress. * Simplified ChildElementRange * Share buffer * Fixup deserializer row/col itertor * Fixup Deserialize Calibration_Matrix * Started moving out 'SetSkeletonSettings' from 'SerializerApi' to 'SettingsSerializer'. It compiles but there are some diffs. * Fixed Marker/Weight skeleton serialization issue * Removed 'SetSkeletonSettings' from 'SerializerApi', moved to 'SettingsSerializer'. * Remove unused helper functions. * Removing unnecessary newlines. * Cleaned up SerializerApi.h * Cleaned up SerializerApi.h * Removed variable decimal count * Removed calls to std::to_string * Adding 'cstring' include to 'RTProtocol.cpp'. * Change to 'sprintf_s' variant. * Added 'algorithm' include to 'Settings.cpp'. * Updating to 'snprintf'. * Fixed use of overlapping buffer with snprintf * Compiler warnings are gone when building using mingw in Windows. * Updating code for creating 'mErrorStr' to remove compiler warning. * Updating code for creating 'mErrorStr' to remove compiler warning. * Remove whitespace. * Changing to 'snprintf'. * Updating print calls to remove compiler issues. * Changing from 'int' to 'size_t' type in for-loops. * Update so that it works to build using Visual Studio and 'GNU'. * Add 'if(WIN32)' to CMakeLists.txt target_link_libraries code to fix broken building when using Ubuntu terminal. * Remove 'build_test' folder. * Remove includes, start adding 'std::' instead. * Add 'include <stdint.h>' to 'Settings.h'. * Revert back to previous include 'cstdint'. * Revert 'cstring' include in 'MarkupSerializer.cpp'. * Reverting another include. * Re-introduce include to 'DesierializerApi.h' but instead include 'cstdint'. * Reintroduce '#include <algorithm>' to 'SettingsDeserializer.cpp'. * Adding 'std::' in front of 'size_t' instances that were missing it. --------- Co-authored-by: johannes.gotlen <[email protected]> * Added accidentally deleted spaces. * Added accidentally deleted spaces. * Removed serializer interfaces * Fixed SerializerApi memory leak * Various minor changes. * Minor changes. * Fixed errors while handling input parameters in SettingsSerializer * use sizeof instead of repeating size literal * Added extra line breaks * Reintroduced settings of 'tinyxml2_BUILD_TESTING' to OFF. * Changed tests cmake version requirement to match the parent project * Updated README.md * Removing unnecessary newline. * Remove two unnecessary comments. * Remove unnecessary double newlines from top of RTPRotocol.cpp. * Replace c-style cast with static_cast. * Remove unnecessary spaces. * Remove one newline from two locations with double newlines. * DeserializerApi: Made mPtr private * Formatting change * Change from '.0f' to '0.0f'. * Remove commented-out line of code. * fixed bug detecting invalid chars * Auto formatted new files * Removed unused includes * Renamed SerializerApi -> Serializer, DeserializerApi -> Deserializer * Removed raw pointers, removed retained state in SettingsDeserializer * Fixed inconsistent line breaks * Deserializer, updated private member order * Added missing formal parameter name in Deserialize6DOFSettings * Removed comments from SettingsDeserializer --------- Co-authored-by: Oliver Glandberger <[email protected]> Co-authored-by: Oliver Glandberger <[email protected]>
1 parent 6747d81 commit 37473aa

35 files changed

+4633
-6266
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "external/tinyxml2"]
2+
path = external/tinyxml2
3+
url = https://github.com/leethomason/tinyxml2.git
4+
branch = v10.0.0

CMakeLists.txt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,34 @@ option(${PROJECT_NAME}_BUILD_TESTS "Build tests" OFF)
66

77
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
88

9+
set(tinyxml2_BUILD_TESTING OFF)
10+
add_subdirectory(external/tinyxml2)
11+
912
add_library(${PROJECT_NAME}
10-
Markup.cpp
1113
Network.cpp
1214
RTPacket.cpp
1315
RTProtocol.cpp
1416
Settings.cpp
15-
MarkupSerializer.cpp
17+
Serializer.cpp
18+
Deserializer.cpp
19+
SettingsDeserializer.cpp
20+
SettingsSerializer.cpp
1621
)
1722

1823
target_include_directories(${PROJECT_NAME} PUBLIC
1924
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
2025
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
2126
)
2227

23-
target_link_libraries(${PROJECT_NAME}
24-
PUBLIC $<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">:ws2_32.lib>
25-
)
28+
if(WIN32)
29+
target_link_libraries(${PROJECT_NAME}
30+
PUBLIC
31+
$<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">:ws2_32.lib iphlpapi.lib>
32+
$<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","GNU">:ws2_32 iphlpapi>
33+
)
34+
endif()
35+
target_link_libraries(${PROJECT_NAME} PRIVATE tinyxml2::tinyxml2)
36+
2637

2738
# Enable C++14
2839
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
@@ -81,6 +92,7 @@ if (${PROJECT_NAME}_BUILD_EXAMPLES)
8192
)
8293
target_link_libraries(RigidBodyStreaming
8394
qualisys_cpp_sdk
95+
tinyxml2
8496
)
8597
endif ()
8698

CMakeSettings.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "x64-Debug",
5+
"generator": "Ninja",
6+
"configurationType": "Debug",
7+
"inheritEnvironments": [ "msvc_x64_x64" ],
8+
"buildRoot": "${projectDir}\\out\\build\\${name}",
9+
"installRoot": "${projectDir}\\out\\install\\${name}",
10+
"cmakeCommandArgs": "",
11+
"buildCommandArgs": "",
12+
"ctestCommandArgs": "",
13+
"variables": [
14+
{
15+
"name": "qualisys_cpp_sdk_BUILD_TESTS",
16+
"value": "True",
17+
"type": "BOOL"
18+
}
19+
]
20+
}
21+
]
22+
}

Deserializer.cpp

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
#include "Deserializer.h"
2+
3+
#include <algorithm>
4+
#include <tinyxml2.h>
5+
6+
qualisys_cpp_sdk::Deserializer::Deserializer(std::shared_ptr<tinyxml2::XMLDocument> document,
7+
tinyxml2::XMLElement* element)
8+
: mDocument(document), mPtr(element)
9+
{
10+
}
11+
12+
qualisys_cpp_sdk::Deserializer::Deserializer(const char* data)
13+
{
14+
mDocument = std::make_shared<tinyxml2::XMLDocument>();
15+
mDocument->Parse(data);
16+
mPtr = mDocument->RootElement();
17+
}
18+
19+
qualisys_cpp_sdk::Deserializer qualisys_cpp_sdk::Deserializer::FindChild(const char* elementName) const
20+
{
21+
return {mDocument, mPtr->FirstChildElement(elementName)};
22+
}
23+
24+
qualisys_cpp_sdk::Deserializer qualisys_cpp_sdk::Deserializer::FindNextSibling(const char* elementName) const
25+
{
26+
return {mDocument, mPtr->NextSiblingElement(elementName)};
27+
}
28+
29+
double qualisys_cpp_sdk::Deserializer::ReadAttributeDouble(const char* attributeName, double defaultValue) const
30+
{
31+
return mPtr->DoubleAttribute(attributeName, defaultValue);
32+
}
33+
34+
std::uint32_t qualisys_cpp_sdk::Deserializer::ReadAttributeUnsignedInt(const char* attributeName,
35+
std::uint32_t defaultValue) const
36+
{
37+
return mPtr->UnsignedAttribute(attributeName, defaultValue);
38+
}
39+
40+
std::int32_t qualisys_cpp_sdk::Deserializer::ReadAttributeInt(const char* attributeName,
41+
std::int32_t defaultValue) const
42+
{
43+
return mPtr->IntAttribute(attributeName, defaultValue);
44+
}
45+
46+
bool qualisys_cpp_sdk::Deserializer::ReadAttributeBool(const char* attributeName, bool defaultValue) const
47+
{
48+
return mPtr->BoolAttribute(attributeName, defaultValue);
49+
}
50+
51+
bool qualisys_cpp_sdk::Deserializer::operator==(const Deserializer& other) const
52+
{
53+
return mPtr == other.mPtr;
54+
}
55+
56+
bool qualisys_cpp_sdk::Deserializer::operator!=(const Deserializer& other) const
57+
{
58+
return mPtr != other.mPtr;
59+
}
60+
61+
qualisys_cpp_sdk::Deserializer::operator bool() const
62+
{
63+
return mPtr != nullptr;
64+
}
65+
66+
int qualisys_cpp_sdk::Deserializer::ReadInt(std::int32_t defaultValue) const
67+
{
68+
return mPtr->IntText(defaultValue);
69+
}
70+
71+
unsigned int qualisys_cpp_sdk::Deserializer::ReadUnsignedInt(std::int32_t defaultValue) const
72+
{
73+
return mPtr->UnsignedText(defaultValue);
74+
}
75+
76+
float qualisys_cpp_sdk::Deserializer::ReadFloat(float defaultValue) const
77+
{
78+
return mPtr->FloatText(defaultValue);
79+
}
80+
81+
std::string qualisys_cpp_sdk::Deserializer::ReadAttributeString(const char* name) const
82+
{
83+
if (auto charPtr = mPtr->Attribute(name))
84+
{
85+
return {charPtr};
86+
}
87+
88+
return {};
89+
}
90+
91+
float qualisys_cpp_sdk::Deserializer::ReadAttributeFloat(const char* name, float defaultValue) const
92+
{
93+
return mPtr->FloatAttribute(name, defaultValue);
94+
}
95+
96+
std::string qualisys_cpp_sdk::Deserializer::ReadString() const
97+
{
98+
if (auto charPtr = mPtr->GetText())
99+
{
100+
return {charPtr};
101+
}
102+
103+
return {};
104+
}
105+
106+
qualisys_cpp_sdk::ChildElementRange::ChildElementRange(Deserializer& parent, const char* elementName)
107+
: mParent(parent), mElementName(elementName)
108+
{
109+
}
110+
111+
qualisys_cpp_sdk::ChildElementRange::Iterator::Iterator(const ChildElementRange& range)
112+
: mCurrent(nullptr), mChildElementRange(range)
113+
{
114+
}
115+
116+
qualisys_cpp_sdk::ChildElementRange::Iterator::Iterator(const ChildElementRange& range, std::size_t index)
117+
: mCurrent(nullptr), mChildElementRange(range)
118+
{
119+
mCurrent = range.mParent.FindChild(mChildElementRange.mElementName);
120+
}
121+
122+
qualisys_cpp_sdk::Deserializer qualisys_cpp_sdk::ChildElementRange::Iterator::operator*() const
123+
{
124+
return mCurrent;
125+
}
126+
127+
qualisys_cpp_sdk::ChildElementRange::Iterator& qualisys_cpp_sdk::ChildElementRange::Iterator::operator++()
128+
{
129+
mCurrent = mCurrent.FindNextSibling(mChildElementRange.mElementName);
130+
return *this;
131+
}
132+
133+
bool qualisys_cpp_sdk::ChildElementRange::Iterator::operator!=(const Iterator& other) const
134+
{
135+
return mCurrent != other.mCurrent;
136+
}
137+
138+
qualisys_cpp_sdk::ChildElementRange::Iterator qualisys_cpp_sdk::ChildElementRange::begin() const
139+
{
140+
return Iterator(*this, 0);
141+
}
142+
143+
qualisys_cpp_sdk::ChildElementRange::Iterator qualisys_cpp_sdk::ChildElementRange::end() const
144+
{
145+
return Iterator(*this);
146+
}
147+
148+
bool qualisys_cpp_sdk::Deserializer::TryReadElementDouble(const char* elementName, double& output) const
149+
{
150+
if (auto childElem = FindChild(elementName))
151+
{
152+
return childElem.mPtr->QueryDoubleText(&output) == tinyxml2::XML_SUCCESS;
153+
}
154+
155+
return false;
156+
}
157+
158+
bool qualisys_cpp_sdk::Deserializer::TryReadElementFloat(const char* elementName, float& output) const
159+
{
160+
if (auto childElem = FindChild(elementName))
161+
{
162+
return childElem.mPtr->QueryFloatText(&output) == tinyxml2::XML_SUCCESS;
163+
}
164+
165+
return false;
166+
}
167+
168+
bool qualisys_cpp_sdk::Deserializer::TryReadElementUnsignedInt32(const char* elementName,
169+
std::uint32_t& output) const
170+
{
171+
if (auto childElem = FindChild(elementName))
172+
{
173+
return childElem.mPtr->QueryUnsignedText(&output) == tinyxml2::XML_SUCCESS;
174+
}
175+
176+
return false;
177+
}
178+
179+
bool qualisys_cpp_sdk::Deserializer::TryReadElementString(const char* elementName, std::string& output) const
180+
{
181+
output.clear();
182+
183+
if (auto childElem = FindChild(elementName))
184+
{
185+
if (auto charPtr = childElem.mPtr->GetText())
186+
{
187+
output = charPtr;
188+
}
189+
return true;
190+
}
191+
192+
return false;
193+
}
194+
195+
namespace
196+
{
197+
void RemoveInvalidChars(std::string& str)
198+
{
199+
auto isInvalidChar = [](int c) -> int
200+
{
201+
// iscntrl: control codes(NUL, etc.), '\t', '\n', '\v', '\f', '\r', backspace (DEL)
202+
// isspace: some common checks but also 0x20 (SPACE)
203+
// return != 0 --> invalid char
204+
return std::iscntrl(c) != 0 || std::isspace(c) != 0;
205+
};
206+
str.erase(std::remove_if(str.begin(), str.end(), isInvalidChar), str.end());
207+
}
208+
}
209+
210+
bool qualisys_cpp_sdk::Deserializer::TryReadElementBool(const std::string& element, bool& value) const
211+
{
212+
auto xmlElem = FindChild(element.c_str());
213+
if (!xmlElem)
214+
{
215+
return false;
216+
}
217+
218+
auto str = std::string(xmlElem.mPtr->GetText());
219+
RemoveInvalidChars(str);
220+
str = ToLowerXmlString(str);
221+
222+
if (str == "true")
223+
{
224+
value = true;
225+
}
226+
else if (str == "false")
227+
{
228+
value = false;
229+
}
230+
else
231+
{
232+
// Don't change value, just report error.
233+
return false;
234+
}
235+
236+
return true;
237+
}
238+
239+
std::string qualisys_cpp_sdk::ToLowerXmlString(std::string& str)
240+
{
241+
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c)
242+
{
243+
return static_cast<unsigned char>(std::tolower(c));
244+
});
245+
return str;
246+
}

0 commit comments

Comments
 (0)