NCBI C++ ToolKit
enumerated.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef ENUMERATED__HPP
2 #define ENUMERATED__HPP
3 
4 /* $Id: enumerated.hpp 79560 2017-09-20 17:04:38Z gouriano $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Eugene Vasilchenko
30 *
31 * File Description:
32 * !!! PUT YOUR DESCRIPTION HERE !!!
33 */
34 
35 #include <serial/impl/stdtypes.hpp>
36 #include <serial/enumvalues.hpp>
37 #include <limits>
38 
39 
40 /** @addtogroup TypeInfoCPP
41  *
42  * @{
43  */
44 
45 
47 
48 
50 {
52 public:
53  // values should exist for all live time of our instance
54  CEnumeratedTypeInfo(size_t size, const CEnumeratedTypeValues* values,
55  bool sign = false);
56 
57  const CEnumeratedTypeValues& Values(void) const
58  {
59  return m_Values;
60  }
61 
62  virtual bool IsDefault(TConstObjectPtr object) const override;
63  virtual bool Equals(TConstObjectPtr , TConstObjectPtr,
64  ESerialRecursionMode how = eRecursive) const override;
65  virtual void SetDefault(TObjectPtr dst) const override;
66  virtual void Assign(TObjectPtr dst, TConstObjectPtr src,
67  ESerialRecursionMode how = eRecursive) const override;
68 
69  virtual bool IsSigned(void) const override;
70 
71  virtual Int4 GetValueInt4(TConstObjectPtr objectPtr) const override;
72  virtual Uint4 GetValueUint4(TConstObjectPtr objectPtr) const override;
73  virtual void SetValueInt4(TObjectPtr objectPtr, Int4 value) const override;
74  virtual void SetValueUint4(TObjectPtr objectPtr, Uint4 value) const override;
75 
76  virtual Int8 GetValueInt8(TConstObjectPtr objectPtr) const override;
77  virtual Uint8 GetValueUint8(TConstObjectPtr objectPtr) const override;
78  virtual void SetValueInt8(TObjectPtr objectPtr, Int8 value) const override;
79  virtual void SetValueUint8(TObjectPtr objectPtr, Uint8 value) const override;
80 
81  virtual void GetValueString(TConstObjectPtr objectPtr,
82  string& value) const override;
83  virtual void SetValueString(TObjectPtr objectPtr,
84  const string& value) const override;
85 
86 protected:
87  static TObjectPtr CreateEnum(TTypeInfo objectType,
88  CObjectMemoryPool* memoryPool);
89  static void ReadEnum(CObjectIStream& in,
90  TTypeInfo objectType, TObjectPtr objectPtr);
91  static void WriteEnum(CObjectOStream& out,
92  TTypeInfo objectType, TConstObjectPtr objectPtr);
93  static void SkipEnum(CObjectIStream& in, TTypeInfo objectType);
94  static void CopyEnum(CObjectStreamCopier& copier, TTypeInfo objectType);
95 
96 private:
99 };
100 
101 template<typename T>
102 inline
104  const CEnumeratedTypeValues* values)
105 {
106 // C++ enums are not signed and not unsigned
107  bool is_signed = std::is_signed<T>::value;
109  for (const auto& v : values->GetValues()) {
110  if (v.second < 0) {
111  is_signed = true;
112  break;
113  }
114  }
115  }
116  return new CEnumeratedTypeInfo(sizeof(T), values, is_signed);
117 }
118 
119 
121 
122 /* @} */
123 
124 #endif /* ENUMERATED__HPP */
CObjectIStream –.
Definition: objistr.hpp:92
Recursively.
Definition: serialdef.hpp:191
virtual Int8 GetValueInt8(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:404
#define T(s)
Definition: common.h:225
unsigned NCBI_INT8_TYPE Uint8
Unsigned 8 byte sized integer.
Definition: ncbitype.h:146
signed int Int4
Alias for signed int.
Definition: ncbitype.h:120
unsigned int Uint4
Alias for unsigned int.
Definition: ncbitype.h:121
CEnumeratedTypeInfo * CreateEnumeratedTypeInfo(const T &, const CEnumeratedTypeValues *values)
Definition: enumerated.hpp:103
std::ofstream out("events_result.xml")
main entry point for tests
virtual void SetValueUint4(TObjectPtr objectPtr, Uint4 value) const
Definition: stdtypes.cpp:398
CObjectOStream –.
Definition: objostr.hpp:82
CObjectStreamCopier –.
Definition: objcopy.hpp:70
signed NCBI_INT8_TYPE Int8
Signed 8 byte sized integer.
Definition: ncbitype.h:143
virtual Int4 GetValueInt4(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:380
virtual Uint8 GetValueUint8(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:416
virtual void SetDefault(TObjectPtr dst) const override
Set object to default value.
Definition: stdtypes.cpp:347
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const override
Set object to copy of another one.
Definition: stdtypes.cpp:358
virtual Uint4 GetValueUint4(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:392
const void * TConstObjectPtr
Definition: serialdef.hpp:59
virtual bool Equals(TConstObjectPtr, TConstObjectPtr, ESerialRecursionMode how=eRecursive) const override
Check if both objects contain the same values.
Definition: stdtypes.cpp:352
virtual void GetValueString(TConstObjectPtr objectPtr, string &value) const
Definition: stdtypes.cpp:460
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
const CEnumeratedTypeValues & m_Values
Definition: enumerated.hpp:98
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:190
virtual void SetValueUint8(TObjectPtr objectPtr, Uint8 value) const
Definition: stdtypes.cpp:422
const TValues & GetValues(void) const
Get the list of name-value pairs.
Definition: enumvalues.hpp:98
int size
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1410
virtual void SetValueString(TObjectPtr objectPtr, const string &value) const
Definition: stdtypes.cpp:466
virtual void SetValueInt4(TObjectPtr objectPtr, Int4 value) const
Definition: stdtypes.cpp:386
char value[7]
Definition: config.c:428
virtual void SetValueInt8(TObjectPtr objectPtr, Int8 value) const
Definition: stdtypes.cpp:410
virtual bool IsDefault(TConstObjectPtr object) const override
Check, whether the object contains default value.
Definition: stdtypes.cpp:342
const CPrimitiveTypeInfo * m_ValueType
Definition: enumerated.hpp:97
CPrimitiveTypeInfo CParent
Definition: enumerated.hpp:51
const CEnumeratedTypeValues & Values(void) const
Definition: enumerated.hpp:57
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:74
virtual bool IsSigned(void) const
std::istream & in(std::istream &in_, double &x_)
void * TObjectPtr
Definition: serialdef.hpp:55
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
Modified on Sun Nov 19 16:44:15 2017 by modify_doxy.py rev. 546573