-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify BaseClass, Integer, Boolean with generated classes
Signed-off-by: Thomas Günther <[email protected]>
- Loading branch information
Showing
6 changed files
with
127 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.