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

Go to the SVN repository for this file.

1 #ifndef OBJECTS_OBJMGR___BLOB_ID__HPP
2 #define OBJECTS_OBJMGR___BLOB_ID__HPP
3 
4 /* $Id: blob_id.hpp 91296 2020-10-06 16:24:16Z 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 * Class used for identification of top level Seq-entries,
33 * also known as TSEs and blobs.
34 *
35 */
36 
37 #include <corelib/ncbiobj.hpp>
39 #include <functional>
40 
43 
44 /** @addtogroup ObjectManagerCore
45  *
46  * @{
47  */
48 
49 template<typename Value> struct PConvertToString;
50 
51 template<>
52 struct PConvertToString<int>
53 {
54  string operator()(int v) const
55  {
56  return NStr::IntToString(v);
57  }
58 };
59 
60 
61 template<>
62 struct PConvertToString<const void*>
63 {
64  string operator()(const void* v) const
65  {
66  return NStr::PtrToString(v);
67  }
68 };
69 
70 
71 template<>
73 {
74  const string& operator()(const string& v) const
75  {
76  return v;
77  }
78 };
79 
80 
81 template<>
83 {
84  string operator()(const CSeq_id_Handle& v) const
85  {
86  return v.AsString();
87  }
88 };
89 
90 
92 {
93 public:
94  virtual ~CBlobId(void);
95 
96  /// Get string representation of blob id.
97  /// Should be unique for all blob ids from the same data loader.
98  virtual string ToString(void) const = 0;
99 
100  // Comparison methods
101  virtual bool operator<(const CBlobId& id) const = 0;
102  virtual bool operator==(const CBlobId& id) const;
103 
104 protected:
105  bool LessByTypeId(const CBlobId& id2) const;
106 };
107 
108 
109 template<typename Value, class Converter = PConvertToString<Value> >
110 class CBlobIdFor : public CBlobId
111 {
112 public:
113  typedef Value value_type;
114  typedef Converter convert_to_string_type;
115  typedef CBlobIdFor<Value, Converter> TThisType; // for self reference
116 
118  : m_Value(v)
119  {
120  }
121 
122  const value_type& GetValue(void) const
123  {
124  return m_Value.second();
125  }
126 
127  string ToString(void) const
128  {
129  return m_Value.first()(m_Value.second());
130  }
131 
132  bool operator==(const CBlobId& id_ref) const
133  {
134  const TThisType* id_ptr = dynamic_cast<const TThisType*>(&id_ref);
135  return id_ptr && GetValue() == id_ptr->GetValue();
136  }
137  bool operator<(const CBlobId& id_ref) const
138  {
139  const TThisType* id_ptr = dynamic_cast<const TThisType*>(&id_ref);
140  if ( !id_ptr ) {
141  return this->LessByTypeId(id_ref);
142  }
143  return GetValue() < id_ptr->GetValue();
144  }
145 
146 private:
148 };
149 
150 
155 
156 
158 {
159 public:
160  CBlobIdKey(const CBlobId* id = 0)
161  : m_Id(id)
162  {
163  }
164 
166 
167  const CBlobId& operator*(void) const
168  {
169  return *m_Id;
170  }
171  const CBlobId* operator->(void) const
172  {
173  return m_Id;
174  }
175 
176  string ToString(void) const
177  {
178  return m_Id->ToString();
179  }
180 
181  bool operator<(const CBlobIdKey& id) const
182  {
183  return *m_Id < *id;
184  }
185 
186  bool operator==(const CBlobIdKey& id) const
187  {
188  return *m_Id == *id;
189  }
190  bool operator!=(const CBlobIdKey& id) const
191  {
192  return !(*m_Id == *id);
193  }
194 
195 private:
197 };
198 
199 
201 {
202  return out << id.ToString();
203 }
204 
205 
207 {
208  return out << *id;
209 }
210 
211 
212 /* @} */
213 
216 
217 #endif // OBJECTS_OBJMGR___BLOB_ID__HPP
CObject –.
Definition: ncbiobj.hpp:180
bool operator==(const CEquivRange &A, const CEquivRange &B)
std::ofstream out("events_result.xml")
main entry point for tests
const first_type & first() const
Definition: ncbimisc.hpp:269
const second_type & second() const
Definition: ncbimisc.hpp:278
string
Definition: cgiapp.hpp:687
string AsString(void) const
DECLARE_OPERATOR_BOOL_REF(m_Id)
const value_type & GetValue(void) const
Definition: blob_id.hpp:122
string ToString(void) const
Definition: blob_id.hpp:176
CBlobIdFor< CSeq_id_Handle > CBlobIdSeq_id
Definition: blob_id.hpp:154
bool operator!=(const CBlobIdKey &id) const
Definition: blob_id.hpp:190
string ToString(void) const
Get string representation of blob id.
Definition: blob_id.hpp:127
CBlobIdFor< Value, Converter > TThisType
Definition: blob_id.hpp:115
string operator()(const void *v) const
Definition: blob_id.hpp:64
virtual bool operator<(const CBlobId &id) const =0
CNcbiOstream & operator<<(CNcbiOstream &out, const CBlobId &id)
Definition: blob_id.hpp:200
CConstRef< CBlobId > m_Id
Definition: blob_id.hpp:196
bool operator<(const CBlobId &id_ref) const
Definition: blob_id.hpp:137
CBlobIdFor< int > CBlobIdInt
Definition: blob_id.hpp:151
bool operator==(const CBlobIdKey &id) const
Definition: blob_id.hpp:186
const CBlobId * operator->(void) const
Definition: blob_id.hpp:171
virtual string ToString(void) const =0
Get string representation of blob id.
pair_base_member< convert_to_string_type, value_type > m_Value
Definition: blob_id.hpp:147
CBlobIdKey(const CBlobId *id=0)
Definition: blob_id.hpp:160
const CBlobId & operator*(void) const
Definition: blob_id.hpp:167
bool operator==(const CBlobId &id_ref) const
Definition: blob_id.hpp:132
const string & operator()(const string &v) const
Definition: blob_id.hpp:74
Value value_type
Definition: blob_id.hpp:113
Converter convert_to_string_type
Definition: blob_id.hpp:114
CBlobIdFor< const void * > CBlobIdPtr
Definition: blob_id.hpp:152
CBlobIdFor(const value_type &v)
Definition: blob_id.hpp:117
string operator()(int v) const
Definition: blob_id.hpp:54
CBlobIdFor< string > CBlobIdString
Definition: blob_id.hpp:153
string operator()(const CSeq_id_Handle &v) const
Definition: blob_id.hpp:84
bool operator<(const CBlobIdKey &id) const
Definition: blob_id.hpp:181
bool LessByTypeId(const CBlobId &id2) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static void PtrToString(string &out_str, const void *ptr)
Convert pointer to string.
Definition: ncbistr.cpp:2771
#define NCBI_XOBJMGR_EXPORT
Definition: ncbi_export.h:1307
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2107
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
#define const
Definition: zconf.h:232
Modified on Sun May 19 04:48:36 2024 by modify_doxy.py rev. 669887