Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __CNODE_TSRING_H__
- #define __CNODE_TSTRING_H__
- #include "CNodeBase.h"
- #include "check.h"
- #include <iostream>
- #include "CVector.h"
- //using namespace std;
- namespace CNode_TString
- {
- struct TString {
- CVector<char> iStr;
- };
- std::ostream& operator<<(std::ostream& aOStream, const TString& aTstring);
- std::istream& operator>>(std::istream& aIStream, TString& aTstring);
- class CNode: public CNodeBase
- {
- const ClassInfo<CNode> iInstanceInfo; ///< Instance of the class info for usage statistics
- TString iValue;
- public:
- // c'tors
- /** \brief Implicit c'tor
- * \details Value attributes is set to \c false. Inherited attributes are initialised by CNodeBase implicit c'tor.
- */
- CNode(): CNodeBase(), iValue()
- {}
- /** \brief Conversion c'tor
- * \details Pointer attributes are initialised to the \c this value.
- * \param[in] aValue New encapsulated \c int Value
- */
- explicit CNode(const TString aValue): CNodeBase(), iValue(aValue)
- {}
- /** \brief Copy c'tor
- * \details Create new instance by copying only \p iValue parameter.
- * \param[in] aNode Original instance for copying
- */
- CNode(const CNode& aNode): CNodeBase(), iValue(aNode.Value()) // Explicit calling of CNodeBase is there only for compatibility reason
- {}
- /** \brief String conversion c'tor
- * \details Create new instance from Value in the string. Pointer attributes are initialised to the \c this value.
- * \param[in] aStr Plain C string with value "0" or "1"
- */
- explicit CNode(const char* aStr): CNodeBase(), iValue()
- {
- std::istringstream iss(aStr, std::istringstream::in); iss >> iValue;
- }
- // d'tor
- /** \brief d'tor
- */
- virtual ~CNode()
- {
- iValue = {};
- }
- // InstanceInfo getters
- /** \brief ID getter
- * \return Unique instance ID
- */
- unsigned ID() const
- {
- return(iInstanceInfo.ID());
- }
- // setter/getter
- /** \brief Value setter
- * \param[in] aValue New Value
- * \attention Method generate \c std::range_error exception if parameters \p aValue is out of the \c enum TWeekDay range.
- */
- void SetValue(const TString aValue)
- {
- iValue = aValue;
- }
- /** \brief Value getter
- * \return Actual \c bool \p Value
- */
- TString Value() const
- {
- return(iValue);
- }
- // operators
- /** \brief Complement operator
- * \return CNode instance with complemented attribute Value.
- */
- CNode operator-() const
- {
- //struct TString tmp;
- TString tmp = TString-(Value());
- return CNode(tmp);
- }
- /** \brief Assigment operator
- * \return CNode instance with copied attribute Value.
- */
- CNode& operator=(const CNode& aNode)
- {
- SetValue(aNode.Value()); return(*this);
- }
- /** \brief Comparing by Value operator
- * \return Return \c bool result of comparation
- */
- CVector<char> iStr;
- bool operator==(const TString &aString) const
- {
- if(aString.iStr.Size() != iStr.Size())
- return false;
- for(unsigned i = 0; i < iStr.Size(); ++i)
- {
- if(iStr[i] != aString.iStr[i])
- return false;
- }
- return true;
- }
- /*bool operator==(const CNode& aNode) const
- {
- return(iValue == aNode.Value());
- }
- /** \brief Comparing by Value operator
- * \return Return \c bool result of comparation
- */
- bool operator!=(const CNode& aNode) const
- {
- return(iValue != aNode.Value());
- }
- /** \brief Comparing by Value operator
- * \return Return \c bool result of comparation
- */
- bool operator<(const CNode& aNode) const
- {
- return(iValue < aNode.Value());
- }
- /** \brief Comparing by Value operator
- * \return Return \c bool result of comparation
- */
- bool operator>(const CNode& aNode) const
- {
- return(iValue > aNode.Value());
- }
- /** \brief Output to the stream operator. (\em serialization)
- * \param[in] aOStream Output stream
- * \param[in] aNode Serialized instantion of CNode
- * \return Return \c std::ostream with serialized Value
- */
- friend std::ostream& operator<<(std::ostream& aOStream, const CNode& aNode)
- {
- aOStream << aNode.Value(); return(aOStream);
- }
- /** \brief Input from the stream operator. (\em deserialization)
- * \param[in] aIStream Input stream
- * \param[out] aNode Place for deserialized instantion of CNode
- * \return Return rest of \c std::istream
- */
- friend std::istream& operator>>(std::istream& aIStream, CNode& aNode)
- {
- aIStream >> aNode.iValue; return(aIStream);
- }
- #ifdef CNODE_TEST_VALUES
- // constants for testing CNode functionality
- /** \brief First test value
- * \return Return TWeekDay value (EMonday)
- * \note Useful for automated testing of CNode functionality
- */
- static CVector<char> jStr;
- static TString TestValue0()
- {
- return(jStr);
- }
- /** \brief First test string value
- * \return Return string with TWeekDay value (EMonday)
- * \note Useful for automated testing of CNode functionality
- */
- static const char* TestStringValue0()
- {
- return("(Monday)");
- }
- /** \brief Second test value
- * \return Return TWeekDay value (ETuesday)
- * \note Useful for automated testing of CNode functionality
- */
- static TString TestValue1()
- {
- return jStr;
- }
- /** \brief Second test string value
- * \return Return string with TWeekDay value (ETuesday)
- * \note Useful for automated testing of CNode functionality
- */
- static const char* TestStringValue1()
- {
- return("(Tuesday)");
- }
- /** \brief Random test value
- * \return Return random TWeekDay value
- * \note Useful for automated testing of CNode functionality
- */
- static TString TestValueRandom()
- {
- return;
- }
- /** \brief Random test string value
- * \return Return string with random TWeekDay value
- * \note Useful for automated testing of CNode functionality
- */
- static const char* TestStringValueRandom()
- {
- return;
- }
- #endif /* CNode_TEST_VALUES */
- };
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement