Changeset 748


Ignore:
Timestamp:
10/21/15 13:40:57 (8 years ago)
Author:
rlacroix
Message:

CType<T>: Add a conversion operator to const reference.

Location:
XIOS/trunk/src/type
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/type/type.hpp

    r591 r748  
    1313 
    1414  template <typename T> class CType_ref ; 
    15      
    16   template <typename T>  
     15 
     16  template <typename T> 
    1717  class CType : public  virtual CBaseType 
    1818  { 
    1919    public: 
    20    
     20 
    2121    CType(void) ; 
    2222    CType(const T& val) ; 
     
    3535    CType& operator = (const CType_ref<T>& val) ; 
    3636    operator T&() ; 
    37      
     37    operator const T&() const ; 
     38 
    3839    inline virtual CBaseType* clone(void) const   { return _clone(); } 
    3940    virtual void fromString(const string& str)   { _fromString(str); } 
     
    4243    virtual bool toBuffer(CBufferOut& buffer) const { return _toBuffer(buffer); } 
    4344    virtual void reset(void) { _reset(); } 
    44     virtual bool isEmpty() const { return _isEmpty(); }  
     45    virtual bool isEmpty() const { return _isEmpty(); } 
    4546    virtual size_t size(void) const { return _size(); } 
    46      
     47 
    4748    void allocate(void) ; 
    4849    void checkEmpty(void) const; 
    49         
     50 
    5051    T* ptrValue ; 
    5152    bool empty ; 
    52        
    53     friend class CType_ref<T> ;  
    54   
     53 
     54    friend class CType_ref<T> ; 
     55 
    5556    private : 
    56   
     57 
    5758    CType* _clone(void) const; 
    5859    void _fromString(const string& str) ; 
     
    6162    bool _toBuffer(CBufferOut& buffer) const; 
    6263    void _reset(void) ; 
    63     bool _isEmpty() const ;   
     64    bool _isEmpty() const ; 
    6465    size_t _size(void) const ; 
    65   
     66 
    6667  } ; 
    6768 
    6869 
    6970  template<typename T> class CType ; 
    70      
    71   template <typename T>  
     71 
     72  template <typename T> 
    7273  class CType_ref : public virtual CBaseType 
    7374  { 
    7475    public: 
    75    
     76 
    7677    CType_ref(void) ; 
    7778    CType_ref(T& val) ; 
     
    8990    void set_ref(CType<T>& val) ; 
    9091    void set_ref(const CType_ref& val) ; 
    91      
     92 
    9293    const CType_ref& operator = (T& val) const ; 
    9394    const CType_ref& operator = (CType<T>& val) const ; 
     
    103104    virtual bool toBuffer(CBufferOut& buffer) const { return _toBuffer(buffer); } 
    104105    virtual void reset(void) { _reset(); } 
    105     virtual bool isEmpty() const { return _isEmpty(); }  
     106    virtual bool isEmpty() const { return _isEmpty(); } 
    106107    virtual size_t size(void) const { return _size(); } 
    107108 
    108109    void checkEmpty(void) const; 
    109      
     110 
    110111 
    111112    T mutable * ptrValue ; 
    112113    bool empty ; 
    113114    friend class CType<T> ; 
    114      
     115 
    115116    private : 
    116      
     117 
    117118    CType_ref* _clone(void) const; 
    118119    void _fromString(const string& str) ; 
     
    123124    bool _toBuffer(CBufferOut& buffer) const; 
    124125    void _reset(void) ; 
    125     bool _isEmpty() const ;   
     126    bool _isEmpty() const ; 
    126127    size_t _size(void) const ; 
    127128  } ; 
    128    
    129    
     129 
     130 
    130131  class CMessage ; 
    131    
     132 
    132133  template <typename T> 
    133134  CBufferOut& operator<<(CBufferOut& buffer, const CType<T>& type) ; 
     
    135136  template <typename T> 
    136137  CBufferOut& operator<<(CBufferOut& buffer, const CType_ref<T>& type) ; 
    137    
     138 
    138139  template <typename T> 
    139140  CBufferOut& operator<<(CBufferOut& buffer, const T& type) ; 
    140    
     141 
    141142  template <typename T> 
    142143  CBufferOut& operator<<(CBufferOut& buffer, T& type) ; 
     
    158159  template <typename T> 
    159160  CMessage& operator<<(CMessage& msg, const CType_ref<T>& type) ; 
    160 */   
    161    
     161*/ 
     162 
    162163  template <typename T> 
    163164  CMessage& operator<<(CMessage& msg, const T& type) ; 
  • XIOS/trunk/src/type/type_impl.hpp

    r680 r748  
    1313namespace xios 
    1414{ 
    15   
     15 
    1616  using namespace std; 
    17    
     17 
    1818  template <typename T> 
    1919  CType<T>::CType(void) 
     
    2121    empty=true ; 
    2222  } 
    23      
     23 
    2424  template <typename T> 
    2525  CType<T>::CType(const T& val) 
     
    2828    set(val) ; 
    2929  } 
    30    
     30 
    3131  template <typename T> 
    3232  CType<T>::CType(const CType<T>& type) 
     
    4141    empty=true ; 
    4242    set(type) ; 
    43   }   
    44    
     43  } 
     44 
    4545  template <typename T> 
    4646  void CType<T>::set(const T& val) 
    4747  { 
    48     if (empty)  
    49     {  
     48    if (empty) 
     49    { 
    5050      ptrValue = new T(val) ; 
    5151      empty=false ; 
     
    6161    { 
    6262      if (empty) 
    63       {  
     63      { 
    6464        ptrValue = new T(*type.ptrValue) ; 
    6565        empty=false ; 
     
    7676    { 
    7777      if (empty) 
    78       {  
     78      { 
    7979        ptrValue = new T(*type.ptrValue) ; 
    8080        empty=false ; 
     
    9797    return *ptrValue ; 
    9898  } 
    99    
     99 
    100100  template <typename T> 
    101101  CType<T>& CType<T>::operator = (const T& val) 
     
    104104    return *this ; 
    105105  } 
    106    
     106 
    107107  template <typename T> 
    108108  CType<T>& CType<T>::operator = (const CType<T>& type) 
     
    111111    return *this ; 
    112112  } 
    113    
     113 
    114114  template <typename T> 
    115115  CType<T>& CType<T>::operator = (const CType_ref<T>& type) 
     
    118118    return *this ; 
    119119  } 
    120    
     120 
    121121   template <typename T> 
    122122   CType<T>::operator T&() 
     123   { 
     124    checkEmpty(); 
     125    return *ptrValue ; 
     126   } 
     127 
     128   template <typename T> 
     129   CType<T>::operator const T&() const 
    123130   { 
    124131    checkEmpty(); 
     
    133140   } 
    134141 
    135    
     142 
    136143  template <typename T> 
    137144  void CType<T>::_fromString(const string& str) 
     
    147154    return sizeof(T) ; 
    148155  } 
    149    
     156 
    150157  template <typename T> 
    151158  bool CType<T>::_isEmpty(void) const 
     
    153160    return empty ; 
    154161  } 
    155    
     162 
    156163  template <typename T> 
    157164  string CType<T>::_toString(void) const 
     
    162169    return oss.str() ; 
    163170  } 
    164    
     171 
    165172  template <typename T> 
    166173  bool CType<T>::_toBuffer(CBufferOut& buffer) const 
     
    169176    return buffer.put(*ptrValue) ; 
    170177  } 
    171    
     178 
    172179  template <typename T> 
    173180  bool CType<T>::_fromBuffer(CBufferIn& buffer) 
     
    176183    return buffer.get(*ptrValue) ; 
    177184  } 
    178   
     185 
    179186 
    180187  template <typename T> 
    181188  void CType<T>::allocate(void) 
    182189  { 
    183     if (empty)  
     190    if (empty) 
    184191    { 
    185192      ptrValue = new T ; 
     
    187194    } 
    188195  } 
    189    
     196 
    190197  template <typename T> 
    191198  void CType<T>::_reset(void) 
    192199  { 
    193     if (!empty)  
     200    if (!empty) 
    194201    { 
    195202      delete ptrValue ; 
     
    197204    } 
    198205  } 
    199    
     206 
    200207  template <typename T> 
    201208  void CType<T>::checkEmpty(void) const 
    202209  { 
    203210    if (empty) ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << "Data is not initialized") ; 
    204   }   
    205  
    206    
     211  } 
     212 
     213 
    207214  template <typename T> 
    208215  CBufferOut& operator<<(CBufferOut& buffer, const CType<T>& type) 
Note: See TracChangeset for help on using the changeset viewer.