Start working on build system.
This commit is contained in:
parent
4b308f6c32
commit
521486be62
88 changed files with 1065 additions and 349 deletions
|
@ -0,0 +1,28 @@
|
|||
#include "XmlAttribute.h"
|
||||
|
||||
XmlAttribute::XmlAttribute(const std::string& name)
|
||||
: mName(name),
|
||||
mValue()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
XmlAttributePtr XmlAttribute::Create(const std::string& name)
|
||||
{
|
||||
return std::make_unique<XmlAttribute>(name);
|
||||
}
|
||||
|
||||
const std::string& XmlAttribute::getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
const std::string& XmlAttribute::getValue() const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
void XmlAttribute::setValue(const std::string& value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
23
src/base/core/serialization/xml/xml-elements/XmlAttribute.h
Normal file
23
src/base/core/serialization/xml/xml-elements/XmlAttribute.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class XmlAttribute
|
||||
{
|
||||
public:
|
||||
XmlAttribute(const std::string& name);
|
||||
|
||||
static std::unique_ptr<XmlAttribute> Create(const std::string& name);
|
||||
|
||||
const std::string& getName() const;
|
||||
|
||||
const std::string& getValue() const;
|
||||
|
||||
void setValue(const std::string& value);
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mValue;
|
||||
};
|
||||
|
||||
using XmlAttributePtr = std::unique_ptr<XmlAttribute>;
|
140
src/base/core/serialization/xml/xml-elements/XmlElement.cpp
Normal file
140
src/base/core/serialization/xml/xml-elements/XmlElement.cpp
Normal file
|
@ -0,0 +1,140 @@
|
|||
#include "XmlElement.h"
|
||||
|
||||
#include "XmlAttribute.h"
|
||||
|
||||
XmlElement::XmlElement(const std::string& tagName)
|
||||
: mTagName(tagName),
|
||||
mChildren()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
XmlElement::~XmlElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
XmlElementPtr XmlElement::Create(const std::string& tagName)
|
||||
{
|
||||
return std::make_unique<XmlElement>(tagName);
|
||||
}
|
||||
|
||||
void XmlElement::setTagName(const std::string& tagName)
|
||||
{
|
||||
mTagName = tagName;
|
||||
}
|
||||
|
||||
void XmlElement::addChild(XmlElementPtr child)
|
||||
{
|
||||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
void XmlElement::addAttribute(XmlAttributePtr attribute)
|
||||
{
|
||||
mAttributes[attribute->getName()] = std::move(attribute);
|
||||
}
|
||||
|
||||
void XmlElement::addAttribute(const std::string& name, const std::string& value)
|
||||
{
|
||||
auto attr = std::make_unique<XmlAttribute>(name);
|
||||
attr->setValue(value);
|
||||
addAttribute(std::move(attr));
|
||||
}
|
||||
|
||||
const std::string& XmlElement::getTagName() const
|
||||
{
|
||||
return mTagName;
|
||||
}
|
||||
|
||||
const std::string& XmlElement::getText() const
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
|
||||
void XmlElement::setText(const std::string& text)
|
||||
{
|
||||
mText = text;
|
||||
}
|
||||
|
||||
XmlElement* XmlElement::getFirstChildWithTagName(const std::string& tag)
|
||||
{
|
||||
for(auto& child : mChildren)
|
||||
{
|
||||
if (child->getTagName() == tag)
|
||||
{
|
||||
return child.get();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool XmlElement::hasAttribute(const std::string& attribute) const
|
||||
{
|
||||
return (bool)(getAttribute(attribute));
|
||||
}
|
||||
|
||||
XmlAttribute* XmlElement::getAttribute(const std::string& attributeName) const
|
||||
{
|
||||
if (auto iter = mAttributes.find(attributeName); iter != mAttributes.end())
|
||||
{
|
||||
return iter->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, XmlAttributePtr>& XmlElement::getAttributes() const
|
||||
{
|
||||
return mAttributes;
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<XmlElement> >& XmlElement::getChildren() const
|
||||
{
|
||||
return mChildren;
|
||||
}
|
||||
|
||||
std::string XmlElement::toString(unsigned depth, bool keepInline) const
|
||||
{
|
||||
const auto prefix = std::string(2*depth, ' ');
|
||||
|
||||
std::string line_ending = keepInline ? "" : "\n";
|
||||
|
||||
auto content = prefix + "<" + getTagName();
|
||||
for (const auto& [key, attribute] : getAttributes())
|
||||
{
|
||||
content += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
|
||||
}
|
||||
|
||||
const auto num_children = mChildren.size();
|
||||
if (num_children == 0 && getText().empty())
|
||||
{
|
||||
content += "/>" + line_ending;
|
||||
return content;
|
||||
}
|
||||
else
|
||||
{
|
||||
content += ">";
|
||||
}
|
||||
|
||||
if (!getText().empty())
|
||||
{
|
||||
content += getText();
|
||||
}
|
||||
|
||||
if (num_children>0)
|
||||
{
|
||||
content += line_ending;
|
||||
}
|
||||
|
||||
for(const auto& child : mChildren)
|
||||
{
|
||||
content += child->toString(depth+1, keepInline);
|
||||
}
|
||||
if (num_children>0)
|
||||
{
|
||||
content += prefix;
|
||||
}
|
||||
|
||||
content += "</" + getTagName() + ">" + line_ending;
|
||||
return content;
|
||||
}
|
47
src/base/core/serialization/xml/xml-elements/XmlElement.h
Normal file
47
src/base/core/serialization/xml/xml-elements/XmlElement.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class XmlAttribute;
|
||||
using XmlAttributePtr = std::unique_ptr<XmlAttribute>;
|
||||
|
||||
class XmlElement
|
||||
{
|
||||
public:
|
||||
XmlElement(const std::string& tagName);
|
||||
virtual ~XmlElement();
|
||||
|
||||
static std::unique_ptr<XmlElement> Create(const std::string& tagName);
|
||||
|
||||
void addAttribute(XmlAttributePtr attribute);
|
||||
void addAttribute(const std::string& name, const std::string& value);
|
||||
void addChild(std::unique_ptr<XmlElement> child);
|
||||
|
||||
const std::string& getTagName() const;
|
||||
const std::string& getText() const;
|
||||
|
||||
bool hasAttribute(const std::string& attribute) const;
|
||||
XmlAttribute* getAttribute(const std::string& attribute) const;
|
||||
const std::unordered_map<std::string, XmlAttributePtr>& getAttributes() const;
|
||||
|
||||
const std::vector<std::unique_ptr<XmlElement> >& getChildren() const;
|
||||
|
||||
XmlElement* getFirstChildWithTagName(const std::string& tag);
|
||||
|
||||
void setText(const std::string& text);
|
||||
void setTagName(const std::string& tagName);
|
||||
|
||||
virtual std::string toString(unsigned depth = 0, bool keepInline = false) const;
|
||||
|
||||
protected:
|
||||
std::string mTagName;
|
||||
std::string mText;
|
||||
|
||||
std::unordered_map<std::string, XmlAttributePtr> mAttributes;
|
||||
std::vector<std::unique_ptr<XmlElement> > mChildren;
|
||||
};
|
||||
|
||||
using XmlElementPtr = std::unique_ptr<XmlElement>;
|
55
src/base/core/serialization/xml/xml-elements/XmlProlog.cpp
Normal file
55
src/base/core/serialization/xml/xml-elements/XmlProlog.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "XmlProlog.h"
|
||||
|
||||
#include "XmlAttribute.h"
|
||||
|
||||
XmlProlog::XmlProlog(const std::string& tagName)
|
||||
: XmlElement(tagName),
|
||||
mVersion(XmlProlog::Version::V1_0),
|
||||
mEncoding(XmlProlog::Encoding::UTF8)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
XmlPrologPtr XmlProlog::Create(const std::string& tagName)
|
||||
{
|
||||
return std::make_unique<XmlProlog>(tagName);
|
||||
}
|
||||
|
||||
XmlProlog::Encoding XmlProlog::getEncoding() const
|
||||
{
|
||||
return mEncoding;
|
||||
}
|
||||
|
||||
XmlProlog::Version XmlProlog::getVersion() const
|
||||
{
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
void XmlProlog::setEncoding(const std::string& encoding)
|
||||
{
|
||||
if(encoding == "UTF-8")
|
||||
{
|
||||
mEncoding = XmlProlog::Encoding::UTF8;
|
||||
}
|
||||
}
|
||||
|
||||
void XmlProlog::setVersion(const std::string& version)
|
||||
{
|
||||
if(version == "1.0")
|
||||
{
|
||||
mVersion = XmlProlog::Version::V1_0;
|
||||
}
|
||||
}
|
||||
|
||||
void XmlProlog::update()
|
||||
{
|
||||
if(const auto version = getAttribute("version"))
|
||||
{
|
||||
setVersion(version->getValue());
|
||||
}
|
||||
|
||||
if(const auto encoding = getAttribute("encoding"))
|
||||
{
|
||||
setEncoding(encoding->getValue());
|
||||
}
|
||||
}
|
36
src/base/core/serialization/xml/xml-elements/XmlProlog.h
Normal file
36
src/base/core/serialization/xml/xml-elements/XmlProlog.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include "XmlElement.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class XmlProlog : public XmlElement
|
||||
{
|
||||
public:
|
||||
enum class Version{
|
||||
V1_0
|
||||
};
|
||||
|
||||
enum class Encoding{
|
||||
UTF8
|
||||
};
|
||||
|
||||
public:
|
||||
XmlProlog(const std::string& tagName);
|
||||
|
||||
static std::unique_ptr<XmlProlog> Create(const std::string& tagName);
|
||||
|
||||
Encoding getEncoding() const;
|
||||
Version getVersion() const;
|
||||
|
||||
void setEncoding(const std::string& encoding);
|
||||
void setVersion(const std::string& version);
|
||||
void update();
|
||||
|
||||
private:
|
||||
Version mVersion;
|
||||
Encoding mEncoding;
|
||||
};
|
||||
|
||||
using XmlPrologPtr = std::unique_ptr<XmlProlog>;
|
Loading…
Add table
Add a link
Reference in a new issue