Toward core module compiling.

This commit is contained in:
jmsgrogan 2023-12-27 12:20:02 +00:00
parent c25a56ee19
commit 3ed195d7dd
305 changed files with 1774 additions and 1065 deletions

View file

@ -7,9 +7,9 @@ XmlAttribute::XmlAttribute(const String& name)
}
XmlAttributePtr XmlAttribute::Create(const String& name)
Ptr<XmlAttribute> XmlAttribute::Create(const String& name)
{
return std::make_unique<XmlAttribute>(name);
return Ptr<XmlAttribute>::create(name);
}
const String& XmlAttribute::getName() const

View file

@ -1,6 +1,6 @@
#pragma once
#include "Memory.h"
#include "Pointer.h"
#include "String.h"
class XmlAttribute
@ -19,5 +19,3 @@ private:
String mName;
String mValue;
};
using XmlAttributePtr = Ptr<XmlAttribute>;

View file

@ -14,9 +14,9 @@ XmlElement::~XmlElement()
}
XmlElementPtr XmlElement::Create(const String& tagName)
Ptr<XmlElement> XmlElement::Create(const String& tagName)
{
return std::make_unique<XmlElement>(tagName);
return Ptr<XmlElement>::create(tagName);
}
void XmlElement::setTagName(const String& tagName)
@ -24,19 +24,19 @@ void XmlElement::setTagName(const String& tagName)
mTagName = tagName;
}
void XmlElement::addChild(XmlElementPtr child)
void XmlElement::addChild(Ptr<XmlElement> child)
{
mChildren.push_back(std::move(child));
}
void XmlElement::addAttribute(XmlAttributePtr attribute)
void XmlElement::addAttribute(Ptr<XmlAttribute> attribute)
{
mAttributes[attribute->getName()] = std::move(attribute);
mAttributes.insert(attribute->getName(), std::move(attribute));
}
void XmlElement::addAttribute(const String& name, const String& value)
{
auto attr = std::make_unique<XmlAttribute>(name);
auto attr = Ptr<XmlAttribute>::create(name);
attr->setValue(value);
addAttribute(std::move(attr));
}
@ -74,16 +74,30 @@ bool XmlElement::hasAttribute(const String& attribute) const
return (bool)(getAttribute(attribute));
}
XmlAttribute* XmlElement::getAttribute(const String& attributeName) const
const XmlAttribute* XmlElement::getAttribute(const String& attributeName) const
{
if (auto iter = mAttributes.find(attributeName); iter != mAttributes.end())
{
return iter->second.get();
return (*iter).value().get();
}
return nullptr;
}
const std::unordered_map<String, XmlAttributePtr>& XmlElement::getAttributes() const
XmlAttribute* XmlElement::getAttribute(const String& attributeName)
{
if (auto iter = mAttributes.find(attributeName); iter != mAttributes.end())
{
//return (*iter).value().get();
}
return nullptr;
}
void XmlElement::forEachAttribute(eachAttrFunc func) const
{
}
const Map<String, Ptr<XmlAttribute> >& XmlElement::getAttributes() const
{
return mAttributes;
}
@ -102,18 +116,18 @@ String XmlElement::toString(unsigned depth, bool keepInline) const
auto content = prefix + "<" + getTagName();
for (const auto& [key, attribute] : getAttributes())
{
content += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
content += _s(" ") + attribute->getName() + _s("=\"") + attribute->getValue() + _s("\"");
}
const auto num_children = mChildren.size();
if (num_children == 0 && getText().empty())
{
content += "/>" + line_ending;
content += _s("/>") + line_ending;
return content;
}
else
{
content += ">";
content += _s(">");
}
if (!getText().empty())
@ -135,6 +149,6 @@ String XmlElement::toString(unsigned depth, bool keepInline) const
content += prefix;
}
content += "</" + getTagName() + ">" + line_ending;
content += _s("</") + getTagName() + _s(">") + line_ending;
return content;
}

View file

@ -14,15 +14,20 @@ public:
static Ptr<XmlElement> Create(const String& tagName);
void addAttribute(XmlAttributePtr attribute);
void addAttribute(Ptr<XmlAttribute> attribute);
void addAttribute(const String& name, const String& value);
void addChild(Ptr<XmlElement> child);
const String& getTagName() const;
const String& getText() const;
XmlAttribute* getAttribute(const String& attribute) const;
const Map<Ptr<XmlAttribute> >& getAttributes() const;
using eachAttrFunc = std::function<bool(const String& key, const XmlAttribute& attr)>;
void forEachAttribute(eachAttrFunc func) const;
const XmlAttribute* getAttribute(const String& attribute) const;
XmlAttribute* getAttribute(const String& attribute);
const Map<String, Ptr<XmlAttribute> >& getAttributes() const;
const Vector<Ptr<XmlElement> >& getChildren() const;
@ -39,6 +44,6 @@ protected:
String mTagName;
String mText;
Map<Ptr<XmlAttributePtr> > mAttributes;
Map<String, Ptr<XmlAttribute> > mAttributes;
Vector<Ptr<XmlElement> > mChildren;
};

View file

@ -10,9 +10,9 @@ XmlProlog::XmlProlog(const String& tagName)
}
XmlPrologPtr XmlProlog::Create(const String& tagName)
Ptr<XmlProlog> XmlProlog::Create(const String& tagName)
{
return std::make_unique<XmlProlog>(tagName);
return Ptr<XmlProlog>::create(tagName);
}
XmlProlog::Encoding XmlProlog::getEncoding() const

View file

@ -2,7 +2,7 @@
#include "XmlElement.h"
#include "Memory.h"
#include "Pointer.h"
#include "Vector.h"
class XmlProlog : public XmlElement
@ -31,6 +31,4 @@ public:
private:
Version mVersion;
Encoding mEncoding;
};
using XmlPrologPtr = Ptr<XmlProlog>;
};