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:93
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
#define T(s)
Definition: common.h:230
std::ofstream out("events_result.xml")
main entry point for tests
const TValues & GetValues(void) const
Get the list of name-value pairs.
Definition: enumvalues.hpp:98
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
void * TObjectPtr
Definition: serialdef.hpp:55
const void * TConstObjectPtr
Definition: serialdef.hpp:59
@ eRecursive
Recursively.
Definition: serialdef.hpp:192
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsDefault(TConstObjectPtr object) const override
Check, whether the object contains default value.
Definition: stdtypes.cpp:383
virtual Uint4 GetValueUint4(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:433
virtual bool Equals(TConstObjectPtr, TConstObjectPtr, ESerialRecursionMode how=eRecursive) const override
Check if both objects contain the same values.
Definition: stdtypes.cpp:393
virtual void SetDefault(TObjectPtr dst) const override
Set object to default value.
Definition: stdtypes.cpp:388
virtual void SetValueInt8(TObjectPtr objectPtr, Int8 value) const
Definition: stdtypes.cpp:451
virtual void SetValueInt4(TObjectPtr objectPtr, Int4 value) const
Definition: stdtypes.cpp:427
virtual void GetValueString(TConstObjectPtr objectPtr, string &value) const
Definition: stdtypes.cpp:501
const CPrimitiveTypeInfo * m_ValueType
Definition: enumerated.hpp:97
virtual Int4 GetValueInt4(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:421
const CEnumeratedTypeValues & m_Values
Definition: enumerated.hpp:98
virtual void SetValueUint8(TObjectPtr objectPtr, Uint8 value) const
Definition: stdtypes.cpp:463
virtual void SetValueUint4(TObjectPtr objectPtr, Uint4 value) const
Definition: stdtypes.cpp:439
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const override
Set object to copy of another one.
Definition: stdtypes.cpp:399
virtual bool IsSigned(void) const
virtual void SetValueString(TObjectPtr objectPtr, const string &value) const
Definition: stdtypes.cpp:507
const CEnumeratedTypeValues & Values(void) const
Definition: enumerated.hpp:57
CPrimitiveTypeInfo CParent
Definition: enumerated.hpp:51
virtual Int8 GetValueInt8(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:445
CEnumeratedTypeInfo * CreateEnumeratedTypeInfo(const T &, const CEnumeratedTypeValues *values)
Definition: enumerated.hpp:103
virtual Uint8 GetValueUint8(TConstObjectPtr objectPtr) const
Definition: stdtypes.cpp:457
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
std::istream & in(std::istream &in_, double &x_)
Modified on Fri Sep 20 14:58:33 2024 by modify_doxy.py rev. 669887