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

Go to the SVN repository for this file.

1 /* $Id: serialasn.cpp 92341 2021-01-11 16:26:27Z 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: Eugene Vasilchenko
27 *
28 * File Description:
29 * Serialization classes.
30 */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 
35 #if HAVE_NCBI_C
36 
38 #include <serial/impl/asntypes.hpp>
40 #include <serial/impl/choice.hpp>
41 #include <serial/serialimpl.hpp>
42 #include <asn.h>
43 
45 
47 {
49 }
50 
52 {
54 }
55 
57 {
59 }
60 
62 {
64 }
65 
67  TAsnNewProc newProc,
68  TAsnFreeProc freeProc,
69  TAsnReadProc readProc,
70  TAsnWriteProc writeProc)
71 {
72  return new COldAsnTypeInfo(name, newProc, freeProc, readProc, writeProc);
73 }
74 
76  CObjectMemoryPool* /*memoryPool*/)
77 {
78  TObjectPtr object = calloc(info->GetSize(), 1);
79  if ( !object )
80  THROW_TRACE(bad_alloc, ());
81  return object;
82 }
83 
84 static const type_info* GetNullId(TConstObjectPtr )
85 {
86  return 0;
87 }
88 
90  size_t size,
91  const type_info& id)
92 {
95  id, &GetNullId);
96 }
97 
98 static TMemberIndex WhichAsn(const CChoiceTypeInfo* /*choiceType*/,
99  TConstObjectPtr choicePtr)
100 {
101  const valnode* node = static_cast<const valnode*>(choicePtr);
102  return node->choice + (kEmptyChoice - 0);
103 }
104 
105 static void SelectAsn(const CChoiceTypeInfo* /*choiceType*/,
106  TObjectPtr choicePtr,
107  TMemberIndex index,
108  CObjectMemoryPool* /*memoryPool*/)
109 {
110  valnode* node = static_cast<valnode*>(choicePtr);
111  node->choice = Uint1(index - (kEmptyChoice - 0));
112 }
113 
114 static void ResetAsn(const CChoiceTypeInfo* /*choiceType*/,
115  TObjectPtr choicePtr)
116 {
117  valnode* node = static_cast<valnode*>(choicePtr);
118  node->choice = 0;
119 }
120 
122 {
123  return CClassInfoHelperBase::CreateChoiceInfo(name, sizeof(valnode),
124  TConstObjectPtr(0), &CreateAsnStruct, typeid(bool),
126 }
127 
129 
130 #endif
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define THROW_TRACE(exception_class, exception_args)
Throw trace.
Definition: ncbiexpt.hpp:477
static CClassTypeInfo * CreateAsnStructInfo(const char *name, size_t size, const type_info &id)
Definition: serialasn.cpp:89
static CChoiceTypeInfo * CreateAsnChoiceInfo(const char *name)
Definition: serialasn.cpp:121
const TMemberIndex kEmptyChoice
Special value for marking empty choice.
Definition: serialdef.hpp:239
static CChoiceTypeInfo * CreateChoiceInfo(const char *name, size_t size, const void *nonCObject, TCreateFunction createFunc, const type_info &ti, TWhichFunction whichFunc, TSelectFunction selectFunc, TResetFunction resetFunc)
Definition: serial.cpp:391
void * TObjectPtr
Definition: serialdef.hpp:55
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const void * TConstObjectPtr
Definition: serialdef.hpp:59
static CClassTypeInfo * CreateClassInfo(const char *name, size_t size, const void *nonCObject, TCreateFunction createFunc, const type_info &id, TGetTypeIdFunction func)
Definition: serial.cpp:417
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static TTypeInfo GetTypeInfo(TTypeInfo base)
Definition: autoptrinfo.cpp:62
TObjectPtr(* TAsnFreeProc)(TObjectPtr)
TTypeInfo CAutoPointerTypeInfoGetTypeInfo(TTypeInfo type)
Definition: serialasn.cpp:51
static TTypeInfo GetTypeInfo(void)
Definition: asntypes.cpp:553
TObjectPtr(* TAsnNewProc)(void)
TTypeInfo CSequenceOfTypeInfoGetTypeInfo(TTypeInfo type)
Definition: serialasn.cpp:61
unsigned char(* TAsnWriteProc)(TObjectPtr, asnio *, asntype *)
TTypeInfo COldAsnTypeInfoGetTypeInfo(const string &name, TAsnNewProc newProc, TAsnFreeProc freeProc, TAsnReadProc readProc, TAsnWriteProc writeProc)
Definition: serialasn.cpp:66
TObjectPtr(* TAsnReadProc)(asnio *, asntype *)
static TTypeInfo GetTypeInfo(TTypeInfo base)
Definition: asntypes.cpp:399
static TTypeInfo GetTypeInfo(TTypeInfo base)
Definition: asntypes.cpp:75
TTypeInfo COctetStringTypeInfoGetTypeInfo(void)
Definition: serialasn.cpp:46
TTypeInfo CSetOfTypeInfoGetTypeInfo(TTypeInfo type)
Definition: serialasn.cpp:56
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::SIZE size
static TObjectPtr CreateAsnStruct(TTypeInfo info, CObjectMemoryPool *)
Definition: serialasn.cpp:75
static void ResetAsn(const CChoiceTypeInfo *, TObjectPtr choicePtr)
Definition: serialasn.cpp:114
static const type_info * GetNullId(TConstObjectPtr)
Definition: serialasn.cpp:84
static TMemberIndex WhichAsn(const CChoiceTypeInfo *, TConstObjectPtr choicePtr)
Definition: serialasn.cpp:98
static void SelectAsn(const CChoiceTypeInfo *, TObjectPtr choicePtr, TMemberIndex index, CObjectMemoryPool *)
Definition: serialasn.cpp:105
Definition: type.c:6
voidp calloc(uInt items, uInt size)
Modified on Tue Nov 28 02:29:58 2023 by modify_doxy.py rev. 669887