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

@ -1,8 +1,5 @@
#include "XmlDocument.h"
#include "XmlProlog.h"
#include "XmlElement.h"
XmlDocument::XmlDocument()
: mProlog(XmlProlog::Create("xml"))
{
@ -19,7 +16,12 @@ void XmlDocument::setProlog(Ptr<XmlProlog> prolog)
mProlog = std::move(prolog);
}
XmlProlog* XmlDocument::getProlog() const
const XmlProlog* XmlDocument::getProlog() const
{
return mProlog.get();
}
XmlProlog* XmlDocument::getProlog()
{
return mProlog.get();
}
@ -29,7 +31,7 @@ void XmlDocument::setRoot(Ptr<XmlElement> root)
mRoot = std::move(root);
}
XmlElement* XmlDocument::getRoot() const
const XmlElement* XmlDocument::getRoot() const
{
return mRoot.get();
}

View file

@ -6,21 +6,19 @@
#include "XmlElement.h"
#include "XmlProlog.h"
class XmlElement;
class XmlProlog;
class XmlDocument
{
public:
XmlDocument();
virtual ~XmlDocument();
XmlProlog* getProlog() const;
XmlElement* getRoot() const;
const XmlProlog* getProlog() const;
XmlProlog* getProlog();
const XmlElement* getRoot() const;
void setProlog(Ptr<XmlProlog> prolog);
void setRoot(Ptr<XmlElement> root);
private:
XmlPrologPtr mProlog;
XmlElementPtr mRoot;
Ptr<XmlProlog> mProlog;
Ptr<XmlElement> mRoot;
};

View file

@ -6,15 +6,13 @@
#include "XmlElement.h"
#include "XmlAttribute.h"
#include <iostream>
using LS = XmlParser::LineState;
using DS = XmlParser::DocumentState;
XmlParser::XmlParser()
: mDocumentState(XmlParser::DocumentState::Await_Prolog),
mLineState(XmlParser::LineState::Await_Tag_Open),
mDocument(XmlDocument::Create()),
mDocument(Ptr<XmlDocument>::create()),
mWorkingElements()
{
@ -22,7 +20,7 @@ XmlParser::XmlParser()
void XmlParser::processLine(const String& input)
{
for (std::size_t idx=0; idx<input.size(); idx++)
for (size_t idx=0; idx<input.size(); idx++)
{
switch (input[idx])
{
@ -301,13 +299,13 @@ void XmlParser::onTagClose()
void XmlParser::onTextStart(char c)
{
mWorkingText = c;
mWorkingText += c;
mLineState = LS::Await_Text_End;
}
void XmlParser::onTextEnd()
{
mWorkingElements.top()->setText(mWorkingText);
(*mWorkingElements.top())->setText(mWorkingText);
}
void XmlParser::onElementTagEnd()
@ -318,7 +316,7 @@ void XmlParser::onElementTagEnd()
void XmlParser::onTagNameStart(char c)
{
mWorkingTagName = c;
mWorkingTagName += c;
mLineState = LS::Await_Tag_Name_End;
if(mDocumentState != DS::Build_Prolog && mDocumentState != DS::Close_Element)
{
@ -344,7 +342,7 @@ void XmlParser::onTagNameEnd()
}
else
{
mWorkingElements.top()->addChild(std::move(new_element));
(*mWorkingElements.top())->addChild(std::move(new_element));
}
mWorkingElements.push(working_element);
mLineState = LS::Await_Attribute_Name;
@ -353,7 +351,7 @@ void XmlParser::onTagNameEnd()
void XmlParser::onAttributeNameStart(char c)
{
mWorkingAttributeName = c;
mWorkingAttributeName += c;
mLineState = LS::Await_Attribute_Name_End;
}
@ -366,7 +364,7 @@ void XmlParser::onAttributeNameEnd()
}
else if(mDocumentState == DS::Build_Element)
{
mWorkingElements.top()->addAttribute(std::move(attribute));
(*mWorkingElements.top())->addAttribute(std::move(attribute));
}
mLineState = LS::Await_Attribute_Value;
}
@ -385,7 +383,7 @@ void XmlParser::onAttributeValueEnd()
}
else if(mDocumentState == DS::Build_Element)
{
mWorkingElements.top()->getAttribute(mWorkingAttributeName)->setValue(mWorkingAttributeValue);
(*mWorkingElements.top())->getAttribute(mWorkingAttributeName)->setValue(mWorkingAttributeValue);
}
mLineState = LS::Await_Attribute_Name;
}
@ -403,7 +401,7 @@ void XmlParser::onFinishProlog()
mLineState = LS::Await_Tag_Open;
}
XmlDocumentPtr XmlParser::getDocument()
Ptr<XmlDocument> XmlParser::getDocument()
{
return std::move(mDocument);
}

View file

@ -1,12 +1,10 @@
#pragma once
#include "String.h"
#include <stack>
#include "Memory.h"
#include "Stack.h"
#include "Pointer.h"
class XmlDocument;
using XmlDocumentPtr = Ptr<XmlDocument>;
class XmlElement;
class XmlParser
@ -38,9 +36,9 @@ public:
public:
XmlParser();
void processLine(const String& input);
Ptr<XmlDocument> getDocument();
XmlDocumentPtr getDocument();
void processLine(const String& input);
private:
void onLeftBracket();
@ -92,8 +90,8 @@ private:
private:
DocumentState mDocumentState;
LineState mLineState;
XmlDocumentPtr mDocument;
std::stack<XmlElement*> mWorkingElements;
Ptr<XmlDocument> mDocument;
Stack<XmlElement*> mWorkingElements;
String mWorkingAttributeName;
String mWorkingTagName;

View file

@ -10,7 +10,7 @@ Status XmlWriter::toString(XmlDocument* document, String& output)
output += "<?xml";
for (const auto& [key, attribute] : prolog->getAttributes())
{
output += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
output += _s(" ") + attribute->getName() + _s("=\"") + attribute->getValue() + _s("\"");
}
output += "?>\n";
}

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>;
};