Skip to content

Commit

Permalink
Unify BaseClass, Integer, Boolean with generated classes
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Günther <[email protected]>
  • Loading branch information
tom-hg57 committed Nov 16, 2024
1 parent 59d8d26 commit 6b480ad
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 141 deletions.
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
31 changes: 12 additions & 19 deletions cimgen/languages/cpp/static/Boolean.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
#ifndef BOOLEAN_H
#define BOOLEAN_H

#include <string>
#include <iostream>
#include <istream>
#include <ostream>

#include "BaseClass.hpp"

namespace CIMPP {
namespace CIMPP
{
/**
* A type with the value space "true" and "false".
*/
class Boolean
{
public:
Boolean();
virtual ~Boolean();
static const BaseClassDefiner declare();
Boolean() : value(false), initialized(false) {}
Boolean(bool value) : value(value), initialized(true) {}

Boolean(bool value);
Boolean& operator=(bool &rop);
friend std::istream& operator>>(std::istream& lop, Boolean& rop);
friend std::ostream& operator<<(std::ostream& os, Boolean& rop);
Boolean& operator=(bool rop);
operator bool();

bool value = false;
bool initialized = false;
bool value;
bool initialized;

static const char debugName[];
virtual const char* debugString();
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>&);
static void addClassAssignFnsToMap(std::unordered_map<std::string, class_assign_function>&);
friend std::istream& operator>>(std::istream& lop, Boolean& rop);
friend std::ostream& operator<<(std::ostream& os, const Boolean& obj);
};
}
#endif
#endif // BOOLEAN_H
96 changes: 49 additions & 47 deletions cimgen/languages/cpp/static/Integer.cpp
Original file line number Diff line number Diff line change
@@ -1,72 +1,74 @@
#include "Integer.hpp"
#include "CIMExceptions.hpp"

using namespace CIMPP;
#include <string>

Integer::Integer(){}
#include "../src/CIMExceptions.hpp"

Integer::~Integer(){}
using namespace CIMPP;

Integer::Integer(long int value)
: value(value), initialized(true) {}
Integer& Integer::operator=(long int rop)
{
value = rop;
initialized = true;
return *this;
}

const BaseClassDefiner Integer::declare() {
return BaseClassDefiner(Integer::addConstructToMap, Integer::addPrimitiveAssignFnsToMap, Integer::addClassAssignFnsToMap, Integer::debugName);
Integer::operator long int()
{
if (!initialized)
{
throw new ReadingUninitializedField();
}
return value;
}

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

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

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

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

namespace CIMPP {
Integer& Integer::operator=(long int &rop){
value = rop;
initialized = true;
return *this;
}

Integer& Integer::operator-=(const Integer& rhs){
value -= rhs.value;
return *this;
}

Integer& Integer::operator*=(const Integer& rhs){
value *= rhs.value;
return *this;
}
Integer& Integer::operator+=(const Integer& rhs)
{
value += rhs.value;
return *this;
}

Integer& Integer::operator/=(const Integer& rhs){
value /= rhs.value;
return *this;
}
Integer& Integer::operator-=(const Integer& rhs)
{
value -= rhs.value;
return *this;
}

Integer& Integer::operator+=(const Integer& rhs){
value += rhs.value;
return *this;
}
Integer& Integer::operator*=(const Integer& rhs)
{
value *= rhs.value;
return *this;
}

Integer::operator long int(){
if(!initialized)
{
throw new ReadingUninitializedField();
}
return value;
}
Integer& Integer::operator/=(const Integer& rhs)
{
value /= rhs.value;
return *this;
}

namespace CIMPP
{
std::istream& operator>>(std::istream& lop, Integer& rop)
{
std::string tmp;
lop >> tmp;

rop.value = stol(tmp);
rop.initialized = true;
return lop;
}

std::ostream& operator<<(std::ostream& os, const Integer& obj)
{
if (obj.initialized)
{
os << obj.value;
}
return os;
}
}
Loading

0 comments on commit 6b480ad

Please sign in to comment.