54 #define NCBI_USE_ERRCODE_X Serial_ASNTypes
68 return ptr =
static_cast<T*
>(
Alloc(
sizeof(
T)));
166 return *nodePtrPtr != 0;
180 return *nodePtrPtr != 0;
193 *nodePtrPtr = nextNodePtr;
194 type->DeleteNode(nodePtr);
195 return nextNodePtr != 0;
206 type->DeleteNode(nodePtr);
207 nodePtr = nextNodePtr;
223 in.BeginContainer(seqType);
230 while (
in.BeginContainerElement(elementType) ) {
239 in.ReadObject(seqType->
Data(node), elementType);
242 nextNodePtr = &seqType->
NextNode(node);
244 in.EndContainerElement();
259 if ( ptrInfo != 0 ) {
273 msg <<
"CSequenceOfTypeInfo: incompatible type: " <<
274 type->GetName() <<
": " <<
typeid(*type).
name() <<
275 " size: " <<
type->GetSize();
282 else if ( asnType->
GetSize() <=
sizeof(dataval) ) {
293 msg <<
"CSequenceOfTypeInfo: incompatible type: " <<
294 type->GetName() <<
": " <<
typeid(*type).
name() <<
295 " size: " <<
type->GetSize();
299 else if (
type->GetSize() <=
sizeof(dataval) ) {
305 msg <<
"CSequenceOfTypeInfo: incompatible type: " <<
306 type->GetName() <<
": " <<
typeid(*type).
name() <<
307 " size: " <<
type->GetSize();
318 &TFunc::CopyIterator, &TFunc::NextElement,
319 &TFunc::GetElementPtr);
324 &TFunc::CopyIterator, &TFunc::NextElement,
325 &TFunc::GetElementPtr,
326 &TFunc::EraseElement, &TFunc::EraseAllElements);
351 return Alloc(
sizeof(valnode));
390 while ( (src =
NextNode(src)) != 0 ) {
435 return Get(
object)->totlen == 0;
441 bytestore* bs1 =
Get(obj1);
442 bytestore* bs2 =
Get(obj2);
443 if ( bs1 == 0 || bs2 == 0 )
447 if (
len != BSLen(bs2) )
452 char buff1[1024], buff2[1024];
457 BSRead(bs1, buff1, chunk);
458 BSRead(bs2, buff2, chunk);
459 if ( memcmp(buff1, buff2, chunk) != 0 )
475 if (
Get(src) == 0 ) {
479 Get(dst) = BSDup(
Get(src));
487 BSFree(
Get(objectPtr));
490 bytestore* bs =
Get(objectPtr) = BSNew(
count);
502 bytestore* bs =
const_cast<bytestore*
>(
Get(objectPtr));
504 out.ThrowError(
out.fIllegalCall,
"null bytestore pointer");
513 BSRead(bs, buff, chunk);
514 block.
Write(buff, chunk);
533 vector<char>&
value)
const
535 bytestore* bs =
const_cast<bytestore*
>(
Get(objectPtr));
546 const vector<char>&
value)
const
549 bytestore* bs =
Get(objectPtr) = BSNew(
count);
550 BSWrite(bs,
const_cast<char*
>(&
value.front()),
count);
567 m_NewProc(newProc), m_FreeProc(freeProc),
568 m_ReadProc(readProc), m_WriteProc(writeProc)
580 m_NewProc(newProc), m_FreeProc(freeProc),
581 m_ReadProc(readProc), m_WriteProc(writeProc)
589 return Get(
object) == 0;
595 return Get(object1) == 0 &&
Get(object2) == 0;
618 in.ThrowError(
in.fFail,
"read fault");
631 out.ThrowError(
out.fFail,
"write fault");
640 if ( !
object || !
data )
649 if ( !
object || !
data )
658 : m_Stream(
out), m_RootTypeName(rootTypeName), m_Ended(
false), m_Count(0)
667 out.ThrowError(
out.fIllegalCall,
668 "incompatible stream format - must be ASN.1 (text or binary)");
672 size_t indent =
out.m_Output.GetIndentLevel();
674 size_t max_indent =
m_AsnIo->max_indent;
675 if (
indent >= max_indent ) {
698 GetStream().Unended(
"AsnIo write error");
711 CObjectOStream::AsnIo::operator asnio*(void)
723 return m_RootTypeName;
729 if ( m_Count == 0 ) {
731 const char* p = (
const char*)memchr(
data,
':', length);
732 if ( p && p[1] ==
':' && p[2] ==
'=' ) {
734 const char* beg =
data;
736 while ( beg < end &&
isspace((
unsigned char) beg[0]) )
738 while ( end > beg &&
isspace((
unsigned char) end[-1]) )
740 if (
string(beg, end) != GetRootTypeName() ) {
741 ERR_POST_X(2,
"AsnWrite: wrong ASN.1 type name: is \""
742 <<
string(beg, end) <<
"\", must be \""
743 << GetRootTypeName() <<
"\"");
746 size_t skip = p + 3 -
data;
748 "AsnWrite: skipping \"" <<
string(
data, skip) <<
"\"");
753 ERR_POST_X(3,
"AsnWrite: no \"Asn-Type ::=\" header (data=\""
758 GetStream().m_Output.PutString(
data, length);
765 #if CHECK_STREAM_INTEGRITY
766 _TRACE(
"WriteBytes: " << length);
767 if (
out.m_CurrentTagState !=
out.eTagStart )
768 out.ThrowError(
out.fIllegalCall,
769 string(
"AsnWrite only allowed at tag start: data= ")+
data);
770 if (
out.m_CurrentTagLimit != 0 &&
out.m_CurrentPosition + length >
out.m_CurrentTagLimit )
771 out.ThrowError(
out.fIllegalCall,
772 string(
"tag DATA overflow: data= ")+
data);
775 out.m_Output.PutString(
data, length);
780 : m_Stream(
in), m_Ended(
false),
781 m_RootTypeName(rootTypeName), m_Count(0)
790 in.ThrowError(
in.fIllegalCall,
791 "incompatible stream format - must be ASN.1 (text or binary)");
794 #if CHECK_STREAM_INTEGRITY
797 if ( sin.m_CurrentTagState != sin.eTagStart ) {
798 in.ThrowError(
in.fIllegalCall,
799 string(
"double tag read: rootTypeName= ")+ rootTypeName);
817 GetStream().Unended(
"AsnIo read error");
825 CObjectIStream::AsnIo::operator asnio*(void)
837 return m_RootTypeName;
844 if ( m_Count == 0 ) {
846 const string& name = GetRootTypeName();
848 count = nameLength + 3;
849 if ( length <
count ) {
850 GetStream().ThrowError(GetStream().
fFail,
851 string(
"buffer too small to put structure name in: name= ")
854 memcpy(
data, name.data(), nameLength);
855 data[nameLength] =
':';
856 data[nameLength + 1] =
':';
857 data[nameLength + 2] =
'=';
862 return count + GetStream().m_Input.ReadLine(
data, length);
865 *
data = GetStream().m_Input.GetChar();
CAliasTypeInfoFunctions TFunc
Int2 LIBCALLBACK ReadAsn(Pointer object, CharPtr data, Uint2 length)
static CSafeStatic< CTypeInfoMap > s_SequenceOfTypeInfo_map
static size_t GetFirstItemOffset(const CItemsInfo &items)
Int2 LIBCALLBACK WriteAsn(Pointer object, CharPtr data, Uint2 length)
static CSafeStatic< CTypeInfoMap > s_SetOfTypeInfo_map
static void * Alloc(size_t size)
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
CObjectIStreamAsnBinary –.
CObjectOStreamAsnBinary –.
static bool NextElement(TIterator &iter)
CContainerTypeInfo::CConstIterator TIterator
static void ReleaseIterator(TIterator &)
static void CopyIterator(TIterator &dst, const TIterator &src)
static TConstObjectPtr GetElementPtr(const TIterator &iter)
static bool InitIterator(TIterator &iter)
static const CSequenceOfTypeInfo * GetType(const TIterator &iter)
static void CopyIterator(TIterator &dst, const TIterator &src)
static const CSequenceOfTypeInfo * GetType(const TIterator &iter)
CContainerTypeInfo::CIterator TIterator
static TObjectPtr GetElementPtr(const TIterator &iter)
static bool InitIterator(TIterator &iter)
static bool EraseElement(TIterator &iter)
static void EraseAllElements(TIterator &iter)
static void ReleaseIterator(TIterator &)
static bool NextElement(TIterator &iter)
static void ReadSequence(CObjectIStream &in, TTypeInfo containerType, TObjectPtr containerPtr)
Root class for all serialization exceptions.
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Warning(CExceptionArgs_Base &args)
const CItemInfo * GetItemInfo(TMemberIndex index) const
TPointerOffsetType GetOffset(void) const
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
const void * TConstObjectPtr
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
ssize_t TPointerOffsetType
static const TObjectType * SafeCast(TTypeInfo type)
ESerialDataFormat
Data file format.
@ ePrimitiveValueSpecial
null, void
@ ePrimitiveValueOctetString
vector<(signed|unsigned)? char>
@ eSerial_AsnText
ASN.1 text.
@ eSerial_AsnBinary
ASN.1 binary.
ESerialDataFormat GetDataFormat(void) const
Get data format.
AsnIo(CObjectIStream &in, const string &rootTypeName)
CObjectOStream & GetStream(void) const
const string & GetRootTypeName(void) const
size_t Read(char *data, size_t length)
void Write(const void *bytes, size_t length)
void Write(const char *data, size_t length)
const string & GetRootTypeName(void) const
#define BEGIN_OBJECT_FRAME_OF2(Stream, Type, Arg)
bool InGoodState(void)
Check fail flags and also the state of input data source.
CObjectIStream & GetStream(void) const
bool InGoodState(void)
Check fail flags and also the state of output stream.
ESerialDataFormat GetDataFormat(void) const
Get data format.
#define END_OBJECT_FRAME_OF(Stream)
AsnIo(CObjectOStream &out, const string &rootTypeName)
size_t Read(void *dst, size_t length, bool forceLength=false)
@ fFail
Internal error, the real reason is unclear.
int16_t Int2
2-byte (16-bit) signed integer
int32_t Int4
4-byte (32-bit) signed integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
int8_t Int1
1-byte (8-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::streamoff CNcbiStreamoff
Portable alias for streamoff.
NCBI_NS_STD::string::size_type SIZE_TYPE
void SetWriteFunction(TTypeWriteFunction func)
const string & GetName(void) const
Get name of this type.
TObjectPtr GetContainerPtr(void) const
const CItemsInfo & GetItems(void) const
ETypeFamily GetTypeFamily(void) const
TTypeInfo GetPointedType(void) const
const CContainerTypeInfo * GetContainerType(void) const
TObjectPtr GetContainerPtr(void) const
const CContainerTypeInfo * GetContainerType(void) const
void SetConstIteratorFunctions(TInitIteratorConst, TReleaseIteratorConst, TCopyIteratorConst, TNextElementConst, TGetElementPtrConst)
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const =0
Set object to copy of another one.
void SetSkipFunction(TTypeSkipFunction func)
void SetCopyFunction(TTypeCopyFunction func)
size_t GetSize(void) const
Get size of data object in memory (like sizeof in C)
TTypeInfo GetElementType(void) const
TObjectPtr Create(CObjectMemoryPool *memoryPool=0) const
Create object of this type on heap (can be deleted by operator delete)
virtual void Delete(TObjectPtr object) const
Delete object.
void SetIteratorFunctions(TInitIterator, TReleaseIterator, TCopyIterator, TNextElement, TGetElementPtr, TEraseElement, TEraseAllElements)
void SetReadFunction(TTypeReadFunction func)
static TObjectPtr & FirstNode(TObjectPtr object)
static TObjectType & Get(TObjectPtr object)
COldAsnTypeInfo(const char *name, TAsnNewProc newProc, TAsnFreeProc freeProc, TAsnReadProc readProc, TAsnWriteProc writeProc)
TObjectPtr(* TAsnFreeProc)(TObjectPtr)
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
static void CopyOctetString(CObjectStreamCopier &copier, TTypeInfo objectType)
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const
Set object to copy of another one.
static void WriteOctetString(CObjectOStream &out, TTypeInfo objectType, TConstObjectPtr objectPtr)
static void ReadOctetString(CObjectIStream &in, TTypeInfo objectType, TObjectPtr objectPtr)
static TTypeInfo GetTypeInfo(void)
CSetOfTypeInfo(TTypeInfo type)
TObjectPtr(* TAsnNewProc)(void)
static TObjectType & Get(TObjectPtr object)
virtual void SetDefault(TObjectPtr dst) const
Set object to default value.
virtual void SetValueOctetString(TObjectPtr objectPtr, const vector< char > &value) const
static void ReadOldAsnStruct(CObjectIStream &in, TTypeInfo objectType, TObjectPtr objectPtr)
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const
Set object to copy of another one.
unsigned char(* TAsnWriteProc)(TObjectPtr, asnio *, asntype *)
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const
Set object to copy of another one.
virtual bool IsDefault(TConstObjectPtr object) const
Check, whether the object contains default value.
COctetStringTypeInfo(void)
void InitSequenceOfTypeInfo(void)
CSequenceOfTypeInfo(TTypeInfo type, bool randomOrder=false)
TObjectPtr(* TAsnReadProc)(asnio *, asntype *)
virtual bool IsDefault(TConstObjectPtr object) const
Check, whether the object contains default value.
static TTypeInfo GetTypeInfo(TTypeInfo base)
TAsnWriteProc m_WriteProc
static void SkipOctetString(CObjectIStream &in, TTypeInfo objectType)
static TTypeInfo GetTypeInfo(TTypeInfo base)
void SetValNodeNext(void)
static void WriteOldAsnStruct(CObjectOStream &out, TTypeInfo objectType, TConstObjectPtr objectPtr)
virtual bool IsDefault(TConstObjectPtr object) const
Check, whether the object contains default value.
virtual void SetDefault(TObjectPtr dst) const
Set object to default value.
virtual void SetDefault(TObjectPtr dst) const
Set object to default value.
virtual bool Equals(TConstObjectPtr obj1, TConstObjectPtr obj2, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
void DeleteNode(TObjectPtr node) const
TObjectPtr CreateNode(void) const
static CTypeInfo * CreateTypeInfo(TTypeInfo base)
TObjectPtr Data(TObjectPtr object) const
static CTypeInfo * CreateTypeInfo(TTypeInfo base)
virtual void GetValueOctetString(TConstObjectPtr objectPtr, vector< char > &value) const
TObjectPtr & NextNode(TObjectPtr object) const
X * NotNull(X *object)
Check for not null value (after C malloc, strdup etc.).
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
while(yy_chk[yy_base[yy_current_state]+yy_c] !=yy_current_state)
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Static variables safety - create on demand, destroy on application termination.
Uint1 Boolean
bool replacment for C
Useful/utility classes and methods.
std::istream & in(std::istream &in_, double &x_)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
voidp calloc(uInt items, uInt size)