Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.19 KB | None | 0 0
  1. #ifndef __CNODE_TSRING_H__
  2. #define __CNODE_TSTRING_H__
  3.  
  4. #include "CNodeBase.h"
  5. #include "check.h"
  6. #include <iostream>
  7. #include "CVector.h"
  8.  
  9. //using namespace std;
  10.  
  11. namespace CNode_TString
  12.     {
  13.  
  14.     struct TString {
  15.  
  16.  
  17.        
  18.         CVector<char> iStr;
  19.  
  20.  
  21.        
  22.  
  23.         };
  24.  
  25.     std::ostream& operator<<(std::ostream& aOStream, const TString& aTstring);
  26.     std::istream& operator>>(std::istream& aIStream, TString& aTstring);
  27.  
  28.  
  29.  
  30.  
  31.     class CNode: public CNodeBase
  32.         {
  33.         const ClassInfo<CNode> iInstanceInfo;   ///< Instance of the class info for usage statistics
  34.         TString iValue;
  35.  
  36.  
  37.  
  38.         public:
  39.  
  40.  
  41.  
  42.             // c'tors
  43.             /** \brief Implicit c'tor
  44.             *  \details Value attributes is set to \c false. Inherited attributes are initialised by CNodeBase implicit c'tor.
  45.             */
  46.  
  47.             CNode(): CNodeBase(), iValue()
  48.  
  49.                 {}
  50.  
  51.             /** \brief Conversion c'tor
  52.             *  \details Pointer attributes are initialised to the \c this value.
  53.             *  \param[in]   aValue New encapsulated \c int Value
  54.             */
  55.             explicit CNode(const TString aValue): CNodeBase(), iValue(aValue)
  56.                 {}
  57.  
  58.             /** \brief Copy c'tor
  59.             *  \details Create new instance by copying only \p iValue parameter.
  60.             *  \param[in]   aNode   Original instance for copying
  61.             */
  62.             CNode(const CNode& aNode): CNodeBase(), iValue(aNode.Value()) // Explicit calling of CNodeBase is there only for compatibility reason
  63.                 {}
  64.  
  65.             /** \brief String conversion c'tor
  66.             *  \details Create new instance from Value in the string. Pointer attributes are initialised to the \c this value.
  67.             *  \param[in] aStr Plain C string with value "0" or "1"
  68.             */
  69.             explicit CNode(const char* aStr): CNodeBase(), iValue()
  70.                 {
  71.                 std::istringstream iss(aStr, std::istringstream::in); iss >> iValue;
  72.                 }
  73.  
  74.             // d'tor
  75.             /** \brief  d'tor
  76.             */
  77.             virtual ~CNode()
  78.                 {
  79.                 iValue = {};
  80.                 }
  81.  
  82.             // InstanceInfo getters
  83.             /** \brief ID getter
  84.             *  \return Unique instance ID
  85.             */
  86.             unsigned ID() const
  87.                 {
  88.                 return(iInstanceInfo.ID());
  89.                 }
  90.  
  91.             // setter/getter
  92.             /** \brief Value setter
  93.             *  \param[in]   aValue  New Value
  94.             *  \attention Method generate \c std::range_error exception if parameters \p aValue is out of the \c enum TWeekDay range.
  95.             */
  96.             void SetValue(const TString aValue)
  97.                 {
  98.  
  99.                 iValue = aValue;
  100.                 }
  101.  
  102.             /** \brief Value getter
  103.             *  \return Actual \c bool \p Value
  104.             */
  105.             TString Value() const
  106.                 {
  107.                 return(iValue);
  108.                 }
  109.  
  110.             // operators
  111.             /** \brief Complement operator
  112.             *  \return CNode instance with complemented attribute Value.
  113.             */
  114.             CNode operator-() const
  115.                 {
  116.                 //struct TString tmp;
  117.                 TString tmp = TString-(Value());
  118.                 return CNode(tmp);
  119.                 }
  120.  
  121.             /** \brief Assigment operator
  122.             *  \return CNode instance with copied attribute Value.
  123.             */
  124.             CNode& operator=(const CNode& aNode)
  125.                 {
  126.                 SetValue(aNode.Value()); return(*this);
  127.                 }
  128.  
  129.             /** \brief Comparing by Value operator
  130.             *  \return Return \c bool result of comparation
  131.             */
  132.  
  133.             CVector<char> iStr;
  134.             bool operator==(const TString &aString) const
  135.                 {
  136.                 if(aString.iStr.Size() != iStr.Size())
  137.                     return false;
  138.                 for(unsigned i = 0; i < iStr.Size(); ++i)
  139.                     {
  140.                     if(iStr[i] != aString.iStr[i])
  141.                         return false;
  142.                     }
  143.                 return true;
  144.                 }
  145.  
  146.  
  147.             /*bool operator==(const CNode& aNode) const
  148.                 {
  149.                 return(iValue == aNode.Value());
  150.                 }
  151.  
  152.                 /** \brief Comparing by Value operator
  153.                 *  \return Return \c bool result of comparation
  154.                 */
  155.             bool operator!=(const CNode& aNode) const
  156.                 {
  157.                 return(iValue != aNode.Value());
  158.                 }
  159.  
  160.             /** \brief Comparing by Value operator
  161.             *  \return Return \c bool result of comparation
  162.             */
  163.             bool operator<(const CNode& aNode) const
  164.                 {
  165.                 return(iValue < aNode.Value());
  166.                 }
  167.  
  168.             /** \brief Comparing by Value operator
  169.             *  \return Return \c bool result of comparation
  170.             */
  171.             bool operator>(const CNode& aNode) const
  172.                 {
  173.                 return(iValue > aNode.Value());
  174.                 }
  175.  
  176.             /** \brief Output to the stream operator. (\em serialization)
  177.             *  \param[in]   aOStream    Output stream
  178.             *  \param[in]   aNode   Serialized instantion of CNode
  179.             *  \return Return \c std::ostream with serialized Value
  180.             */
  181.             friend std::ostream& operator<<(std::ostream& aOStream, const CNode& aNode)
  182.                 {
  183.                 aOStream << aNode.Value(); return(aOStream);
  184.                 }
  185.  
  186.             /** \brief Input from the stream operator. (\em deserialization)
  187.             *  \param[in]   aIStream    Input stream
  188.             *  \param[out]  aNode   Place for deserialized instantion of CNode
  189.             *  \return Return rest of \c std::istream
  190.             */
  191.             friend std::istream& operator>>(std::istream& aIStream, CNode& aNode)
  192.                 {
  193.                 aIStream >> aNode.iValue; return(aIStream);
  194.                 }
  195. #ifdef CNODE_TEST_VALUES
  196.             // constants for testing CNode functionality
  197.  
  198.             /** \brief First test value
  199.             *  \return Return TWeekDay value (EMonday)
  200.             *  \note Useful for automated testing of CNode functionality
  201.             */
  202.             static CVector<char> jStr;
  203.             static TString TestValue0()
  204.                 {
  205.                 return(jStr);
  206.                 }
  207.  
  208.             /** \brief First test string value
  209.             *  \return Return string with TWeekDay value (EMonday)
  210.             *  \note Useful for automated testing of CNode functionality
  211.             */
  212.             static const char* TestStringValue0()
  213.                 {
  214.                 return("(Monday)");
  215.                 }
  216.  
  217.             /** \brief Second test value
  218.             *  \return Return TWeekDay value (ETuesday)
  219.             *  \note Useful for automated testing of CNode functionality
  220.             */
  221.             static TString TestValue1()
  222.                 {
  223.                 return jStr;
  224.                 }
  225.  
  226.             /** \brief Second test string value
  227.             *  \return Return string with TWeekDay value (ETuesday)
  228.             *  \note Useful for automated testing of CNode functionality
  229.             */
  230.             static const char* TestStringValue1()
  231.                 {
  232.                 return("(Tuesday)");
  233.                 }
  234.  
  235.             /** \brief Random test value
  236.             *  \return Return random TWeekDay value
  237.             *  \note Useful for automated testing of CNode functionality
  238.             */
  239.             static TString TestValueRandom()
  240.                 {
  241.                 return;
  242.                 }
  243.  
  244.             /** \brief Random test string value
  245.             *  \return Return string with random TWeekDay value
  246.             *  \note Useful for automated testing of CNode functionality
  247.             */
  248.             static const char* TestStringValueRandom()
  249.                 {
  250.                 return;
  251.                 }
  252.  
  253. #endif /* CNode_TEST_VALUES */
  254.  
  255.  
  256.  
  257.  
  258.  
  259.         };
  260.  
  261.  
  262.     }
  263.  
  264. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement