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

Go to the SVN repository for this file.

1 #ifndef OBJECTTYPE__HPP
2 #define OBJECTTYPE__HPP
3 
4 /* $Id: objecttype.hpp 52309 2011-12-15 19:22:48Z vasilche $
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 <corelib/ncbistd.hpp>
36 #include <serial/objectinfo.hpp>
37 
38 
39 /** @addtogroup ObjHierarchy
40  *
41  * @{
42  */
43 
44 
46 
47 // forward declaration of object tree iterator templates
48 template<class C> class CTypesIteratorBase;
49 template<class LevelIterator> class CTreeIteratorTmpl;
51 class CTreeIterator;
52 
53 // helper template for working with CTypesIterator and CTypesConstIterator
55 {
56 protected:
60 
61  static bool Match(const CObjectTypeInfo& type, TTypeInfo typeInfo)
62  {
63  return type.GetTypeInfo()->IsType(typeInfo);
64  }
65  static bool Match(const CTypesIterator& it, TTypeInfo typeInfo);
66  static bool Match(const CTypesConstIterator& it, TTypeInfo typeInfo);
67  static void AddTo(CTypesIterator& it, TTypeInfo typeInfo);
68  static void AddTo(CTypesConstIterator& it, TTypeInfo typeInfo);
69  static TObjectPtr GetObjectPtr(const CTypesIterator& it);
70  static TConstObjectPtr GetObjectPtr(const CTypesConstIterator& it);
71  static TObjectPtr GetParentObjectPtr(CObjectIStream& in,
72  TTypeInfo typeInfo,
73  size_t max_depth,
74  size_t min_depth);
75 };
76 
77 template<class C>
78 class CType : public CType_Base
79 {
81 public:
84 
85  static TTypeInfo GetTypeInfo(void)
86  {
87  return C::GetTypeInfo();
88  }
89  operator CObjectTypeInfo(void) const
90  {
91  return GetTypeInfo();
92  }
93 
94  static void AddTo(CTypesIterator& it)
95  {
97  }
98  static void AddTo(CTypesConstIterator& it)
99  {
101  }
102 
103  static bool Match(const CObjectTypeInfo& type)
104  {
105  return CParent::Match(type, GetTypeInfo());
106  }
107  static bool Match(const CTypesIterator& it)
108  {
109  return CParent::Match(it, GetTypeInfo());
110  }
111  static bool Match(const CTypesConstIterator& it)
112  {
113  return CParent::Match(it, GetTypeInfo());
114  }
115 
116  static C* Get(const CTypesIterator& it)
117  {
118  if ( !Match(it) )
119  return 0;
121  }
122  static const C* Get(const CTypesConstIterator& it)
123  {
124  if ( !Match(it) )
125  return 0;
127  }
128 
129  static C* GetUnchecked(const CObjectInfo& object)
130  {
131  return &CTypeConverter<C>::Get(object.GetObjectPtr());
132  }
133  static const C* GetUnchecked(const CConstObjectInfo& object)
134  {
135  return &CTypeConverter<C>::Get(object.GetObjectPtr());
136  }
137  static C* Get(const CObjectInfo& object)
138  {
139  if ( !Match(object) )
140  return 0;
141  return GetUnchecked(object);
142  }
143  static const C* Get(const CConstObjectInfo& object)
144  {
145  if ( !Match(object) )
146  return 0;
147  return GetUnchecked(object);
148  }
150  size_t max_depth = 1,
151  size_t min_depth = 1)
152  {
153  return &CTypeConverter<C>::Get
154  (GetParentObjectPtr(in, GetTypeInfo(), max_depth, min_depth));
155  }
156 };
157 
158 
159 /* @} */
160 
161 
163 
164 #endif /* OBJECTTYPE__HPP */
CConstObjectInfo –.
Definition: objectinfo.hpp:421
Class describing stack level of traversal.
Definition: iterator.hpp:118
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
Base class for all iterators over non-modifiable object Do not use it directly.
Definition: iterator.hpp:181
Base class for all iterators over modifiable object.
Definition: iterator.hpp:480
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Template base class for CTypesIterator and CTypesConstIterator Do not use it directly.
Definition: iterator.hpp:565
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define C(s)
Definition: common.h:231
static TObjectType & Get(TObjectPtr object)
Definition: serialutil.hpp:56
void * TObjectPtr
Definition: serialdef.hpp:55
const void * TConstObjectPtr
Definition: serialdef.hpp:59
static TTypeInfo GetTypeInfo(void)
Definition: objecttype.hpp:85
static C * GetParent(CObjectIStream &in, size_t max_depth=1, size_t min_depth=1)
Definition: objecttype.hpp:149
static bool Match(const CTypesConstIterator &it)
Definition: objecttype.hpp:111
static C * Get(const CObjectInfo &object)
Definition: objecttype.hpp:137
static const C * GetUnchecked(const CConstObjectInfo &object)
Definition: objecttype.hpp:133
static void AddTo(CTypesIterator &it, TTypeInfo typeInfo)
Definition: iterator.cpp:431
static TObjectPtr GetParentObjectPtr(CObjectIStream &in, TTypeInfo typeInfo, size_t max_depth, size_t min_depth)
Definition: iterator.cpp:451
static C * Get(const CTypesIterator &it)
Definition: objecttype.hpp:116
CParent::CTypesConstIterator CTypesConstIterator
Definition: objecttype.hpp:83
CType_Base CParent
Definition: objecttype.hpp:80
static C * GetUnchecked(const CObjectInfo &object)
Definition: objecttype.hpp:129
static const C * Get(const CTypesConstIterator &it)
Definition: objecttype.hpp:122
CParent::CTypesIterator CTypesIterator
Definition: objecttype.hpp:82
static bool Match(const CObjectTypeInfo &type)
Definition: objecttype.hpp:103
CTypesIteratorBase< CTreeConstIterator > CTypesConstIterator
Definition: objecttype.hpp:59
static bool Match(const CObjectTypeInfo &type, TTypeInfo typeInfo)
Definition: objecttype.hpp:61
static TObjectPtr GetObjectPtr(const CTypesIterator &it)
Definition: iterator.cpp:441
static bool Match(const CTypesIterator &it)
Definition: objecttype.hpp:107
CTreeIteratorTmpl< CConstTreeLevelIterator > CTreeConstIterator
Definition: objecttype.hpp:58
static void AddTo(CTypesIterator &it)
Definition: objecttype.hpp:94
static void AddTo(CTypesConstIterator &it)
Definition: objecttype.hpp:98
CTypesIteratorBase< CTreeIterator > CTypesIterator
Definition: objecttype.hpp:57
static const C * Get(const CConstObjectInfo &object)
Definition: objecttype.hpp:143
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
std::istream & in(std::istream &in_, double &x_)
Definition: type.c:6
Modified on Fri Sep 20 14:57:55 2024 by modify_doxy.py rev. 669887