X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FRecordType.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FRecordType.cpp;h=1ba4ed81e9611418dc8937f4b46a1aa7108d02d5;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/RecordType.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/RecordType.cpp new file mode 100644 index 000000000..1ba4ed81e --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/RecordType.cpp @@ -0,0 +1,165 @@ +#include "RecordType.h" + +#include "Component.h" + +#include +#include +#include + +namespace Databoard { + namespace Type { + + RecordType::RecordType() + { + } + + RecordType::RecordType(bool referable, std::vector components) + { + this->referable = referable; + + this->components.resize(components.size(), NULL); + + for(int i = 0; i < (int)this->components.size(); ++i) + { + this->components[i] = components[i]; + } + } + + RecordType::~RecordType() + { + for(int i = 0; i < (int)components.size(); ++i) + { + delete components.at(i); + } + + components.clear(); + } + + bool RecordType::isReferable() + { + return referable; + } + + void RecordType::addComponent(std::string name, DataType* type) + { + Component* component = new Component(name, type); + + components.push_back(component); + } + + int RecordType::getComponentIndex(std::string fieldName) + { + for(int i = 0; i < (int)components.size(); ++i) + { + if(components.at(i)->getName() == fieldName) + { + return i; + } + } + + return -1; + } + + Component* RecordType::getComponent(std::string fieldName) + { + for(int i = 0; i < (int)components.size(); ++i) + { + if(components.at(i)->getName() == fieldName) + { + return components.at(i); + } + } + + return NULL; + } + + int RecordType::count() + { + return (int)components.size(); + } + + Component* RecordType::getComponent(int i) + { + return components.at(i); + } + + //std::vector RecordType::getComponents() + //{ + //} + + std::string RecordType::writeOut(int indent) + { + bool isTuple = true; + + for(int i = 0; i < (int)components.size(); ++i) + { + std::istringstream oss(components.at(i)->getName()); + + int name; + + oss >> name; + + if(name != i) + { + isTuple = false; + + break; + } + } + + std::string s; + + if(isTuple == false) + { + s += "{\n"; + } + else + { + s += "( "; + } + + indent += 1; + + for(int i = 0; i < (int)components.size(); ++i) + { + if(isTuple == false) + { + s.append(indent * 2, ' '); + + s += components.at(i)->getName() + " : "; + } + + s += components.at(i)->getDataBoard()->writeOut(indent); + + if(i != ((int)components.size()-1)) + { + s += ","; + } + + if(isTuple == false) + { + s += "\n"; + } + else + { + s += " "; + } + } + + indent -= 1; + + if(isTuple == false) + { + s.append(indent * 2, ' '); + + s += "}"; + } + else + { + s += ")"; + } + + return s; + } + } +}