NCBI C++ ToolKit
AbstractProjectItem.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: AbstractProjectItem.cpp 92824 2021-02-17 16:53:09Z gouriano $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'gbproj.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 #include <serial/objostr.hpp>
43 #include <serial/objistr.hpp>
45 // generated classes
46 
48 
49 BEGIN_objects_SCOPE // namespace ncbi::objects::
50 
51 // destructor
53 {
54 }
55 
56 
58 {
59  const CAbstractProjectItem* item =
60  dynamic_cast<const CAbstractProjectItem*>(&object);
61  if (item && item->m_OtherObject) {
63  (static_cast<CSerialObject*>
65  );
67  }
68 }
69 
70 
72 {
73  const CAbstractProjectItem* item =
74  dynamic_cast<const CAbstractProjectItem*>(&object);
75  if (item) {
76  if (m_OtherObject && item->m_OtherObject) {
77  return m_OtherObject->Equals(*item->m_OtherObject);
78  } else if (m_OtherObject || item->m_OtherObject) {
79  return false;
80  } else {
81  return true;
82  }
83  } else {
84  return false;
85  }
86 }
87 
88 
90 {
91  SetType(object.GetThisTypeInfo()->GetName());
92  m_OtherObject.Reset(&object);
93 }
94 
95 
97 {
98  return *m_OtherObject;
99 }
100 
101 
103 {
104  return m_OtherObject.GetPointer();
105 }
106 
107 
109 {
110  if (m_OtherObject) {
111  CConn_MemoryStream ostr;
112  {{
113  unique_ptr<CObjectOStream> os
116  }}
117 
118  CAbstractProjectItem& mutable_item =
119  const_cast<CAbstractProjectItem&>(*this);
120 
121  vector<char>& data = mutable_item.SetData();
122  data.clear();
123  data.resize(ostr.tellp() - CT_POS_TYPE(0));
124  ostr.read(&data[0], data.size());
125  }
126 }
127 
128 
130 {
131  const string& type = GetType();
132 
133  const CTypeInfo* info{ nullptr };
134  try {
136  }
137  catch (const std::exception&) {
138  // Ignore
139  }
140  if (info) {
141  try {
142  CRef<CSerialObject> ref(static_cast<CSerialObject*>(info->Create()));
144 
145  static const ESerialDataFormat fmts[] = {
148  };
149 
150  for (size_t i = 0; i < sizeof(fmts) / sizeof(ESerialDataFormat); ++i) {
151  try {
152  const TData& data = GetData();
153  string strdata(data.data(), data.size());
154  CNcbiIstrstream istr(strdata);
155  unique_ptr<CObjectIStream> is
156  (CObjectIStream::Open(fmts[i], istr));
157  is->Read(ref, ref->GetThisTypeInfo());
158 
159  m_OtherObject = ref;
160  return;
161  }
162  catch (CSerialException& e) {
163  ERR_POST("CAbstractProjectItem::PostRead(): "
164  "failed to deserialize other item: " << e);
165  }
166  }
167 
168  throw runtime_error("invalid format");
169  }
170  catch (CException& e) {
171  ERR_POST(Error << "failed to deserialize abstract object: " << e);
172  throw;
173  }
174  }
175 }
176 
177 
178 END_objects_SCOPE // namespace ncbi::objects::
179 
181 
182 /* Original file checksum: lines: 57, chars: 1752, CRC32: 436ebd35 */
User-defined methods of the data storage class.
const CSerialObject & Get(void) const
virtual void UserOp_Assign(const CSerialUserOp &source)
Will be called after copying the datatool-generated members.
void PreWrite() const
PreWrite() / PostRead to trap read/write conversion.
virtual bool UserOp_Equals(const CSerialUserOp &object) const
Will be called after comparing the datatool-generated members.
const CSerialObject * GetObject(void) const
CRef< CSerialObject > m_OtherObject
fall-back: non-serialized core object
void Set(CSerialObject &object)
In-memory stream (a la strstream or stringstream)
Root class for all serialization exceptions.
Definition: exception.hpp:50
Base class for all serializable objects.
Definition: serialbase.hpp:150
Base class for user-defined serializable classes to allow for objects assignment and comparison.
Definition: serialbase.hpp:319
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
char data[12]
Definition: iconv.c:80
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
virtual bool Equals(const CSerialObject &object, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 CT_POS_TYPE
Definition: ncbistre.hpp:730
static TTypeInfo GetClassInfoByName(const string &name)
Definition: classinfob.cpp:244
TObjectPtr Create(CObjectMemoryPool *memoryPool=0) const
Create object of this type on heap (can be deleted by operator delete)
TData & SetData(void)
Assign a value to Data data member.
const TType & GetType(void) const
Get the Type member data.
const TData & GetData(void) const
Get the Data member data.
TType & SetType(void)
Assign a value to Type data member.
int i
static MDB_envinfo info
Definition: mdb_load.c:37
Definition: type.c:6
Modified on Sun Jul 14 04:57:50 2024 by modify_doxy.py rev. 669887