Skip to content

Commit

Permalink
Update static cpp sources and parser classes to new generated String …
Browse files Browse the repository at this point in the history
…class; unify BaseClass, Integer, Boolean with generated classes; fix debugstring() in UnknownType

Signed-off-by: Thomas Günther <[email protected]>
  • Loading branch information
tom-hg57 committed Oct 27, 2024
1 parent 85bb999 commit 661425b
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 307 deletions.
106 changes: 0 additions & 106 deletions cimgen/languages/cpp/src/Aliases.hpp

This file was deleted.

2 changes: 0 additions & 2 deletions cimgen/languages/cpp/src/AliasesAssignment.hpp

This file was deleted.

10 changes: 0 additions & 10 deletions cimgen/languages/cpp/src/AliasesTask.hpp

This file was deleted.

11 changes: 2 additions & 9 deletions cimgen/languages/cpp/src/CIMContentHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#include "CIMContentHandler.hpp"

#include <iostream>
#include <sstream>
#include <regex>

#include <stdexcept>

#include "Folders.hpp"
#include "CIMFactory.hpp"
#include "assignments.hpp"
#include "CIMExceptions.hpp"

#ifndef CGMES_BUILD
#include "CIMNamespaces.hpp"
#endif

CIMContentHandler::CIMContentHandler() : Objects(nullptr), RDFMap(nullptr)
{
}
Expand Down Expand Up @@ -133,7 +126,7 @@ void CIMContentHandler::startElement(const std::string &namespaceURI, const std:
}
// Create a task if the XML element is no CIM class and contains a RDF ID
std::string rdf_id = get_rdf_resource(atts);
if(!rdf_id.empty())
if (!rdf_id.empty())
{
taskQueue.push_back(Task(objectStack.top(), qName, rdf_id));
return;
Expand Down
15 changes: 4 additions & 11 deletions cimgen/languages/cpp/src/ModelDescriptionHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#include "ModelDescriptionHandler.hpp"
#include "IEC61970/IEC61970CIMVersion.h"

#ifndef CGMES_BUILD
#include "IEC61970/Base/Domain/String.h"
#include "CIMNamespaces.hpp"
#else
#include "String.hpp"
#endif

#include <stdexcept>
#include <iostream>
#include <string>

#include "CIMExceptions.hpp"
#include "IEC61970/IEC61970CIMVersion.h"

using CIMPP::IEC61970CIMVersion;

Expand All @@ -36,8 +28,9 @@ void ModelDescriptionHandler::startPrefixMapping(const std::string &prefix, cons
{
if(prefix == "cim")
{
std::size_t pos = IEC61970CIMVersion::version.find("CIM");
std::string versionParser = IEC61970CIMVersion::version.substr(pos+3,2);
std::string version = IEC61970CIMVersion::version;
std::size_t pos = version.find("CIM");
std::string versionParser = version.substr(pos+3, 2);

pos = uri.find("cim");
std::string versionFile = uri.substr(pos+3,2);
Expand Down
16 changes: 7 additions & 9 deletions cimgen/languages/cpp/static/BaseClass.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@

#include "BaseClass.hpp"

using namespace CIMPP;

BaseClass::~BaseClass() {}

void BaseClass::addConstructToMap(std::unordered_map<std::string, BaseClass* (*)()>& factory_map) {}

void BaseClass::addPrimitiveAssignFnsToMap(std::unordered_map<std::string, assign_function>& assign_map) {}

void BaseClass::addClassAssignFnsToMap(std::unordered_map<std::string, class_assign_function>& assign_map) {}

const char BaseClass::debugName[] = "BaseClass";
const char* BaseClass::debugString()
const char* BaseClass::debugString() const
{
return BaseClass::debugName;
}

CIMPP::BaseClassDefiner BaseClass::declare() {
void BaseClass::addConstructToMap(std::unordered_map<std::string, BaseClass* (*)()>& factory_map) {}
void BaseClass::addPrimitiveAssignFnsToMap(std::unordered_map<std::string, assign_function>& assign_map) {}
void BaseClass::addClassAssignFnsToMap(std::unordered_map<std::string, class_assign_function>& assign_map) {}

const BaseClassDefiner BaseClass::declare()
{
return BaseClassDefiner(BaseClass::addConstructToMap, BaseClass::addPrimitiveAssignFnsToMap, BaseClass::addClassAssignFnsToMap, BaseClass::debugName);
}
19 changes: 12 additions & 7 deletions cimgen/languages/cpp/static/BaseClass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
#define CGMES_BUILD
#endif

#include <string>
#include <unordered_map>

#include "BaseClassDefiner.hpp"

class BaseClass {
class BaseClass
{
public:
enum cgmesProfile {EQ = 0, SSH = 1, TP = 2, SV = 3, DY = 4, GL = 5, DI = 6};
virtual ~BaseClass();
static CIMPP::BaseClassDefiner declare();
static void addConstructToMap(std::unordered_map<std::string, BaseClass* (*)()>&);
static void addPrimitiveAssignFnsToMap(std::unordered_map<std::string, assign_function>&);
static void addClassAssignFnsToMap(std::unordered_map<std::string, class_assign_function>&);
const static char debugName[];
virtual const char* debugString();

static const char debugName[];
virtual const char* debugString() const;

static void addConstructToMap(std::unordered_map<std::string, BaseClass* (*)()>& factory_map);
static void addPrimitiveAssignFnsToMap(std::unordered_map<std::string, assign_function>& assign_map);
static void addClassAssignFnsToMap(std::unordered_map<std::string, class_assign_function>& assign_map);
static const CIMPP::BaseClassDefiner declare();
};
#endif // BASECLASS_HPP
63 changes: 28 additions & 35 deletions cimgen/languages/cpp/static/Boolean.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#include "Boolean.hpp"
#include "CIMExceptions.hpp"

using namespace CIMPP;

Boolean::Boolean(){}

Boolean::~Boolean(){}
#include <ios>
#include <string>

Boolean::Boolean(bool value)
: value(value), initialized(true) {}
#include "../src/CIMExceptions.hpp"

const BaseClassDefiner Boolean::declare()
{
return BaseClassDefiner(Boolean::addConstructToMap, Boolean::addPrimitiveAssignFnsToMap, Boolean::addClassAssignFnsToMap, Boolean::debugName);
}
using namespace CIMPP;

Boolean& Boolean::operator=(bool &rop)
Boolean& Boolean::operator=(bool rop)
{
value = rop;
initialized = true;
Expand All @@ -24,56 +16,57 @@ Boolean& Boolean::operator=(bool &rop)

Boolean::operator bool()
{
if(!initialized)
if (!initialized)
{
throw new ReadingUninitializedField();
}
return value;
}

void Boolean::addConstructToMap(std::unordered_map<std::string, BaseClass* (*)()>& factory_map) {}

void Boolean::addPrimitiveAssignFnsToMap(std::unordered_map<std::string, assign_function>& assign_map) {}

void Boolean::addClassAssignFnsToMap(std::unordered_map<std::string, class_assign_function>& assign_map) {}

const char Boolean::debugName[] = "Boolean";
const char* Boolean::debugString()
const char* Boolean::debugString() const
{
return Boolean::debugName;
}

namespace CIMPP {
namespace CIMPP
{
std::istream& operator>>(std::istream& lop, Boolean& rop)
{
rop.initialized = false;

std::string tmp;
lop >> tmp;
if(tmp == "true" || tmp == "True" || tmp == "TRUE")

if (tmp == "true" || tmp == "True" || tmp == "TRUE")
{
rop.value = true;
rop.initialized = true;
return lop;
}
if(tmp == "false" || tmp == "False" || tmp == "FALSE")
if (tmp == "false" || tmp == "False" || tmp == "FALSE")
{
rop.value = false;
rop.initialized = true;
return lop;
}
else
{
lop.setstate(std::ios::failbit);
return lop;
}

lop.setstate(std::ios::failbit);
return lop;
}

std::ostream& operator<<(std::ostream& os, Boolean& rop)
std::ostream& operator<<(std::ostream& os, const Boolean& obj)
{
if (rop) {
os << "true";
}
else {
os << "false";
if (obj.initialized)
{
if (obj.value)
{
os << "true";
}
else
{
os << "false";
}
}
return os;
}
Expand Down
Loading

0 comments on commit 661425b

Please sign in to comment.