Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FeatureBranch] Tinyxml2 cleanup #105

Merged
merged 46 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5f1ce17
Removed settings structs from DeserializerAPI
qjgn Feb 7, 2025
e815c17
Serializer wip
qjgn Feb 7, 2025
bd9f54e
restored support for optional force plate corners
qjgn Feb 10, 2025
b974f60
SetSettings6Dof
qjgn Feb 10, 2025
0b0b63b
Fixed incorrect element creation of '2D' and '3D', removed commented …
OliverGlandberger Feb 10, 2025
67df945
Removing unused 'GeneralSettings' function from SerializerApi.h.
OliverGlandberger Feb 10, 2025
1866cf0
Removed 'SetExtTimeBaseSettings' from 'SerializerApi.h' and moved to …
OliverGlandberger Feb 10, 2025
20e5ab3
Removed 'SetExtTimestampSettings' from 'SerializerApi.h', moved to 'S…
OliverGlandberger Feb 10, 2025
1fc4918
Removed 'SetCameraVideoSettings' from 'SerializerApi', moved to 'Sett…
OliverGlandberger Feb 10, 2025
7dd3ccf
Removed 'SetCameraSyncOutSettings' from 'SerializerApi.h', moved to '…
OliverGlandberger Feb 10, 2025
c3bf913
Removed 'SetCameraLensControlSettings' from 'SerializerApi', moved to…
OliverGlandberger Feb 10, 2025
a9ff2f9
Removed 'SetCameraAutoExposureSettings' from 'SerializerApi', moved t…
OliverGlandberger Feb 10, 2025
e867da1
Reformated creation of root elements.
OliverGlandberger Feb 10, 2025
4c64cb3
Renamed deserializer function
qjgn Feb 10, 2025
127dd0d
Merge branch 'tinyxml2_cleanup_1' of https://github.com/qualisys/qual…
OliverGlandberger Feb 10, 2025
5daf6a7
Removed 'SetCameraAutoWhiteBalance' from 'SerializeApi', moved to 'Se…
OliverGlandberger Feb 10, 2025
3f07482
Removed 'SetImageSettings' from 'SerializerApi', moved to 'SettingsSe…
OliverGlandberger Feb 10, 2025
e3c49c2
Removed 'SetForceSettings' from 'SerializerApi', moved to 'SettingsSe…
OliverGlandberger Feb 10, 2025
bfcb8e7
Moved deserializer api TryRead.. functions into class scope
qjgn Feb 10, 2025
48df2e9
Merge branch 'tinyxml2_cleanup_1' of https://github.com/qualisys/qual…
qjgn Feb 10, 2025
3847e60
Renamed deserializer methods
qjgn Feb 10, 2025
85c865b
Renamed deserializer api find element methods
qjgn Feb 10, 2025
e756026
Saving progress.
OliverGlandberger Feb 10, 2025
ee6d18d
Merge branch 'tinyxml2_cleanup_1' of https://github.com/qualisys/qual…
OliverGlandberger Feb 10, 2025
2035825
Simplified ChildElementRange
qjgn Feb 10, 2025
cbb1b72
Share buffer
qjgn Feb 10, 2025
da2820f
Fixup deserializer row/col itertor
qjgn Feb 10, 2025
3693843
Fixup Deserialize Calibration_Matrix
qjgn Feb 10, 2025
2975369
Started moving out 'SetSkeletonSettings' from 'SerializerApi' to 'Set…
OliverGlandberger Feb 10, 2025
c2abe78
Merge branch 'tinyxml2_cleanup_1' of https://github.com/qualisys/qual…
OliverGlandberger Feb 10, 2025
24da1c1
Merge branch 'tinyxml2_cleanup_1' of https://github.com/qualisys/qual…
qjgn Feb 10, 2025
aad5498
Fixed Marker/Weight skeleton serialization issue
qjgn Feb 10, 2025
f8537ec
Removed 'SetSkeletonSettings' from 'SerializerApi', moved to 'Setting…
OliverGlandberger Feb 10, 2025
0345a8a
Remove unused helper functions.
OliverGlandberger Feb 10, 2025
485f705
Removing unnecessary newlines.
OliverGlandberger Feb 10, 2025
1979a43
Cleaned up SerializerApi.h
qjgn Feb 10, 2025
55f0982
Cleaned up SerializerApi.h
qjgn Feb 10, 2025
caf53f6
Removed variable decimal count
qjgn Feb 10, 2025
0b48238
Removed calls to std::to_string
qjgn Feb 10, 2025
b768ed2
Merge branch 'tinyxml2_cleanup_1' of https://github.com/qualisys/qual…
qjgn Feb 10, 2025
e1c3ef9
Adding 'cstring' include to 'RTProtocol.cpp'.
OliverGlandberger Feb 10, 2025
433b568
Merge branch 'tinyxml2_cleanup_1' of https://github.com/qualisys/qual…
OliverGlandberger Feb 10, 2025
6c30464
Change to 'sprintf_s' variant.
OliverGlandberger Feb 10, 2025
e388fae
Added 'algorithm' include to 'Settings.cpp'.
OliverGlandberger Feb 10, 2025
8e42e6a
Updating to 'snprintf'.
OliverGlandberger Feb 10, 2025
4592946
Fixed use of overlapping buffer with snprintf
qjgn Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 43 additions & 80 deletions DeserializerApi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "DeserializerApi.h"
#include "Settings.h"

#include <algorithm>
#include <tinyxml2.h>
Expand All @@ -17,33 +16,33 @@ qualisys_cpp_sdk::DeserializerApi::DeserializerApi(const char* data)
mPtr = mDocument->RootElement();
}

qualisys_cpp_sdk::DeserializerApi qualisys_cpp_sdk::DeserializerApi::FirstChildElement(const char* elementName) const
qualisys_cpp_sdk::DeserializerApi qualisys_cpp_sdk::DeserializerApi::FindChild(const char* elementName) const
{
return {mDocument, mPtr->FirstChildElement(elementName)};
}

qualisys_cpp_sdk::DeserializerApi qualisys_cpp_sdk::DeserializerApi::NextSiblingElement(const char* elementName) const
qualisys_cpp_sdk::DeserializerApi qualisys_cpp_sdk::DeserializerApi::FindNextSibling(const char* elementName) const
{
return {mDocument, mPtr->NextSiblingElement(elementName)};
}

double qualisys_cpp_sdk::DeserializerApi::DoubleAttribute(const char* attributeName, double defaultValue) const
double qualisys_cpp_sdk::DeserializerApi::ReadAttributeDouble(const char* attributeName, double defaultValue) const
{
return mPtr->DoubleAttribute(attributeName, defaultValue);
}

std::uint32_t qualisys_cpp_sdk::DeserializerApi::UnsignedAttribute(const char* attributeName,
std::uint32_t qualisys_cpp_sdk::DeserializerApi::ReadAttributeUnsignedInt(const char* attributeName,
std::uint32_t defaultValue) const
{
return mPtr->UnsignedAttribute(attributeName, defaultValue);
}

std::int32_t qualisys_cpp_sdk::DeserializerApi::IntAttribute(const char* attributeName, std::int32_t defaultValue) const
std::int32_t qualisys_cpp_sdk::DeserializerApi::ReadAttributeInt(const char* attributeName, std::int32_t defaultValue) const
{
return mPtr->IntAttribute(attributeName, defaultValue);
}

bool qualisys_cpp_sdk::DeserializerApi::BoolAttribute(const char* attributeName, bool defaultValue) const
bool qualisys_cpp_sdk::DeserializerApi::ReadAttributeBool(const char* attributeName, bool defaultValue) const
{
return mPtr->BoolAttribute(attributeName, defaultValue);
}
Expand All @@ -63,22 +62,22 @@ qualisys_cpp_sdk::DeserializerApi::operator bool() const
return mPtr != nullptr;
}

int qualisys_cpp_sdk::DeserializerApi::IntText(std::int32_t defaultValue) const
int qualisys_cpp_sdk::DeserializerApi::ReadInt(std::int32_t defaultValue) const
{
return mPtr->IntText(defaultValue);
}

unsigned int qualisys_cpp_sdk::DeserializerApi::UnsignedText(std::int32_t defaultValue) const
unsigned int qualisys_cpp_sdk::DeserializerApi::ReadUnsignedInt(std::int32_t defaultValue) const
{
return mPtr->UnsignedText(defaultValue);
}

float qualisys_cpp_sdk::DeserializerApi::FloatText(float defaultValue) const
float qualisys_cpp_sdk::DeserializerApi::ReadFloat(float defaultValue) const
{
return mPtr->FloatText(defaultValue);
}

std::string qualisys_cpp_sdk::DeserializerApi::Attribute(const char* name) const
std::string qualisys_cpp_sdk::DeserializerApi::ReadAttributeString(const char* name) const
{
if (auto charPtr = mPtr->Attribute(name))
{
Expand All @@ -88,12 +87,12 @@ std::string qualisys_cpp_sdk::DeserializerApi::Attribute(const char* name) const
return {};
}

float qualisys_cpp_sdk::DeserializerApi::FloatAttribute(const char* name, float defaultValue) const
float qualisys_cpp_sdk::DeserializerApi::ReadAttributeFloat(const char* name, float defaultValue) const
{
return mPtr->FloatAttribute(name, defaultValue);
}

std::string qualisys_cpp_sdk::DeserializerApi::GetText() const
std::string qualisys_cpp_sdk::DeserializerApi::ReadString() const
{
if (auto charPtr = mPtr->GetText())
{
Expand All @@ -106,41 +105,36 @@ std::string qualisys_cpp_sdk::DeserializerApi::GetText() const
/// <summary>
/// ChildElementRange
/// </summary>
qualisys_cpp_sdk::ChildElementRange::ChildElementRange(DeserializerApi& parent, const char* elementName) : parent(parent),
elementNameGenerator([elementName](auto& buff, std::size_t, std::size_t) { return elementName; })
qualisys_cpp_sdk::ChildElementRange::ChildElementRange(DeserializerApi& parent, const char* elementName)
: mParent(parent), mElementName(elementName)
{
}

qualisys_cpp_sdk::ChildElementRange::ChildElementRange(DeserializerApi& parent, TElementNameGenerator generator) :
parent(parent), elementNameGenerator(std::move(generator))
qualisys_cpp_sdk::ChildElementRange::Iterator::Iterator(const ChildElementRange& range) : mCurrent(nullptr),
mChildElementRange(range)
{
}

qualisys_cpp_sdk::ChildElementRange::Iterator::Iterator(const ChildElementRange& range) : buffer{}, current(nullptr),
range(range), index(std::numeric_limits<std::size_t>::max())
qualisys_cpp_sdk::ChildElementRange::Iterator::Iterator(const ChildElementRange& range, std::size_t index)
: mCurrent(nullptr), mChildElementRange(range)
{
}

qualisys_cpp_sdk::ChildElementRange::Iterator::Iterator(const ChildElementRange& range, std::size_t index) :
buffer{}, current(nullptr), range(range), index(index)
{
current = range.parent.FirstChildElement(range.elementNameGenerator(buffer, buffSize, index++));
mCurrent = range.mParent.FindChild(mChildElementRange.mElementName);
}

qualisys_cpp_sdk::DeserializerApi qualisys_cpp_sdk::ChildElementRange::Iterator::operator*() const
{
return current;
return mCurrent;
}

qualisys_cpp_sdk::ChildElementRange::Iterator& qualisys_cpp_sdk::ChildElementRange::Iterator::operator++()
{
current = current.NextSiblingElement(range.elementNameGenerator(buffer, buffSize, index++));
mCurrent = mCurrent.FindNextSibling(mChildElementRange.mElementName);
return *this;
}

bool qualisys_cpp_sdk::ChildElementRange::Iterator::operator!=(const Iterator& other) const
{
return current != other.current;
return mCurrent != other.mCurrent;
}

qualisys_cpp_sdk::ChildElementRange::Iterator qualisys_cpp_sdk::ChildElementRange::begin() const
Expand All @@ -153,55 +147,42 @@ qualisys_cpp_sdk::ChildElementRange::Iterator qualisys_cpp_sdk::ChildElementRang
return Iterator(*this);
}


/// <summary>
/// Helper functions
/// </summary>
std::string qualisys_cpp_sdk::ToLowerXmlString(std::string str)
{
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c)
{
return static_cast<unsigned char>(std::tolower(c));
});
return str;
}

bool qualisys_cpp_sdk::TryReadElementDouble(DeserializerApi& element, const char* elementName, double& output)
bool qualisys_cpp_sdk::DeserializerApi::TryReadElementDouble(const char* elementName, double& output) const
{
if (auto childElem = element.FirstChildElement(elementName))
if (auto childElem = FindChild(elementName))
{
return childElem.mPtr->QueryDoubleText(&output) == tinyxml2::XML_SUCCESS;
}

return false;
}

bool qualisys_cpp_sdk::TryReadElementFloat(DeserializerApi& element, const char* elementName, float& output)
bool qualisys_cpp_sdk::DeserializerApi::TryReadElementFloat(const char* elementName, float& output) const
{
if (auto childElem = element.FirstChildElement(elementName))
if (auto childElem = FindChild(elementName))
{
return childElem.mPtr->QueryFloatText(&output) == tinyxml2::XML_SUCCESS;
}

return false;
}

bool qualisys_cpp_sdk::TryReadElementUnsignedInt32(DeserializerApi& element, const char* elementName,
std::uint32_t& output)
bool qualisys_cpp_sdk::DeserializerApi::TryReadElementUnsignedInt32(const char* elementName,
std::uint32_t& output) const
{
if (auto childElem = element.FirstChildElement(elementName))
if (auto childElem = FindChild(elementName))
{
return childElem.mPtr->QueryUnsignedText(&output) == tinyxml2::XML_SUCCESS;
}

return false;
}

bool qualisys_cpp_sdk::TryReadElementString(DeserializerApi& element, const char* elementName, std::string& output)
bool qualisys_cpp_sdk::DeserializerApi::TryReadElementString(const char* elementName, std::string& output) const
{
output.clear();

if (auto childElem = element.FirstChildElement(elementName))
if (auto childElem = FindChild(elementName))
{
if (auto charPtr = childElem.mPtr->GetText())
{
Expand All @@ -228,9 +209,9 @@ namespace
}
}

bool qualisys_cpp_sdk::ReadXmlBool(DeserializerApi xml, const std::string& element, bool& value)
bool qualisys_cpp_sdk::DeserializerApi::TryReadElementBool(const std::string& element, bool& value) const
{
auto xmlElem = xml.FirstChildElement(element.c_str());
auto xmlElem = FindChild(element.c_str());
if (!xmlElem)
{
return false;
Expand All @@ -257,33 +238,15 @@ bool qualisys_cpp_sdk::ReadXmlBool(DeserializerApi xml, const std::string& eleme
return true;
}

qualisys_cpp_sdk::SPosition qualisys_cpp_sdk::ReadSPosition(DeserializerApi& parentElem, const std::string& element)
{
auto positionElem = parentElem.FirstChildElement(element.data());
if (positionElem)
{
return {
positionElem.DoubleAttribute("X"),
positionElem.DoubleAttribute("Y"),
positionElem.DoubleAttribute("Z"),
};
}

return {};
}

qualisys_cpp_sdk::SRotation qualisys_cpp_sdk::ReadSRotation(DeserializerApi& parentElem, const std::string& element)
/// <summary>
/// Helper functions
/// </summary>
/// names
std::string qualisys_cpp_sdk::ToLowerXmlString(std::string& str)
{
auto rotationElem = parentElem.FirstChildElement(element.data());
if (rotationElem)
{
return {
rotationElem.DoubleAttribute("X"),
rotationElem.DoubleAttribute("Y"),
rotationElem.DoubleAttribute("Z"),
rotationElem.DoubleAttribute("W")
};
}

return {};
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c)
{
return static_cast<unsigned char>(std::tolower(c));
});
return str;
}
63 changes: 27 additions & 36 deletions DeserializerApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace tinyxml2

namespace qualisys_cpp_sdk
{
struct SPosition;
struct SRotation;

struct DeserializerApi
{
private:
Expand All @@ -24,45 +21,46 @@ namespace qualisys_cpp_sdk
public:
tinyxml2::XMLElement* mPtr;
DeserializerApi(const char* data);
DeserializerApi FirstChildElement(const char* elementName) const;
DeserializerApi NextSiblingElement(const char* elementName) const;
double DoubleAttribute(const char* attributeName, double defaultValue = 0) const;
std::uint32_t UnsignedAttribute(const char* attributeName, std::uint32_t defaultValue = 0) const;
std::int32_t IntAttribute(const char* attributeName, std::int32_t defaultValue = 0) const;
bool BoolAttribute(const char* attributeName, bool defaultValue = 0) const;

DeserializerApi FindChild(const char* elementName) const;
DeserializerApi FindNextSibling(const char* elementName) const;

bool TryReadElementDouble(const char* elementName, double& output) const;
bool TryReadElementFloat(const char* elementName, float& output) const;
bool TryReadElementUnsignedInt32(const char* elementName, std::uint32_t& output) const ;
bool TryReadElementString(const char* elementName, std::string& output) const;
bool TryReadElementBool(const std::string& element, bool& value) const;

double ReadAttributeDouble(const char* attributeName, double defaultValue = 0) const;
std::uint32_t ReadAttributeUnsignedInt(const char* attributeName, std::uint32_t defaultValue = 0) const;
std::int32_t ReadAttributeInt(const char* attributeName, std::int32_t defaultValue = 0) const;
std::string ReadAttributeString(const char* name) const;
float ReadAttributeFloat(const char* name, float defaultValue = .0f) const;
bool ReadAttributeBool(const char* attributeName, bool defaultValue = 0) const;

std::string ReadString() const;
int ReadInt(std::int32_t defaultValue = 0) const;
unsigned int ReadUnsignedInt(std::int32_t defaultValue = 0) const;
float ReadFloat(float defaultValue = .0f) const;

bool operator==(const DeserializerApi& other) const;
bool operator!=(const DeserializerApi& other) const;
explicit operator bool() const;
int IntText(std::int32_t defaultValue = 0) const;
unsigned int UnsignedText(std::int32_t defaultValue = 0) const;
float FloatText(float defaultValue = .0f) const;
std::string Attribute(const char* name) const;
float FloatAttribute(const char* name, float defaultValue = .0f) const;
std::string GetText() const;
};

struct ChildElementRange
{
static constexpr std::size_t buffSize = 128;
using TElementNameGenerator = std::function<const char*(char (&buff)[buffSize], std::size_t bufferSize,
std::size_t index)>;

private:
DeserializerApi& parent;
TElementNameGenerator elementNameGenerator;

DeserializerApi& mParent;
const char* mElementName;
public:
ChildElementRange() = delete;
ChildElementRange(DeserializerApi& parent, const char* elementName);
ChildElementRange(DeserializerApi& parent,
TElementNameGenerator generator);

struct Iterator
{
char buffer[buffSize];
DeserializerApi current;
const ChildElementRange& range;
std::size_t index;
DeserializerApi mCurrent;
const ChildElementRange& mChildElementRange;
explicit Iterator(const ChildElementRange& range);
Iterator(const ChildElementRange& range, std::size_t index);
DeserializerApi operator*() const;
Expand All @@ -74,12 +72,5 @@ namespace qualisys_cpp_sdk
Iterator end() const;
};

std::string ToLowerXmlString(std::string str);
bool TryReadElementDouble(DeserializerApi& element, const char* elementName, double& output);
bool TryReadElementFloat(DeserializerApi& element, const char* elementName, float& output);
bool TryReadElementUnsignedInt32(DeserializerApi& element, const char* elementName, std::uint32_t& output);
bool TryReadElementString(DeserializerApi& element, const char* elementName, std::string& output);
bool ReadXmlBool(DeserializerApi xml, const std::string& element, bool& value);
SPosition ReadSPosition(DeserializerApi& parentElem, const std::string& element);
SRotation ReadSRotation(DeserializerApi& parentElem, const std::string& element);
std::string ToLowerXmlString(std::string& str);
}
5 changes: 4 additions & 1 deletion RTProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <vector>
#include <iterator>
#include <functional>
#include <cstring>

#include "Network.h"
#include "SettingsDeserializer.h"
Expand Down Expand Up @@ -683,7 +684,9 @@ bool CRTProtocol::GetCapture(const char* pFileName, bool bC3D)
}
else
{
sprintf(mErrorStr, "No packet received. %s.", mErrorStr);
char tmp[sizeof(mErrorStr)];
std::memcpy(tmp, mErrorStr, sizeof(mErrorStr));
(void)snprintf(mErrorStr, sizeof(mErrorStr), "No packet received. %s.", tmp);
}
}
else
Expand Down
Loading