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

Go to the SVN repository for this file.

1 /* $Id: asntypes.cpp 58585 2013-06-18 15:26:09Z grichenk $
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  * !!! PUT YOUR DESCRIPTION HERE !!!
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 
36 #if HAVE_NCBI_C
37 
38 #include <corelib/ncbiutil.hpp>
40 #include <serial/impl/asntypes.hpp>
43 #include <serial/objistr.hpp>
44 #include <serial/objostr.hpp>
45 #include <serial/objistrasnb.hpp>
46 #include <serial/objostrasnb.hpp>
47 #include <serial/objcopy.hpp>
49 #include <serial/impl/typemap.hpp>
50 #include <serial/error_codes.hpp>
51 #include <asn.h>
52 
53 
54 #define NCBI_USE_ERRCODE_X Serial_ASNTypes
55 
57 
58 static inline
59 void* Alloc(size_t size)
60 {
61  return NotNull(calloc(size, 1));
62 }
63 
64 template<class T>
65 static inline
66 T* Alloc(T*& ptr)
67 {
68  return ptr = static_cast<T*>(Alloc(sizeof(T)));
69 }
70 
71 
73 
74 
76 {
77  return s_SequenceOfTypeInfo_map->GetTypeInfo(base, &CreateTypeInfo);
78 }
79 
81 {
82  return new CSequenceOfTypeInfo(base);
83 }
84 
86  : CParent(sizeof(TObjectType), type, randomOrder)
87 {
89 }
90 
92  TTypeInfo type, bool randomOrder)
93  : CParent(sizeof(TObjectType), name, type, randomOrder)
94 {
96 }
97 
99  TTypeInfo type, bool randomOrder)
100  : CParent(sizeof(TObjectType), name, type, randomOrder)
101 {
103 }
104 
105 static
106 size_t GetFirstItemOffset(const CItemsInfo& items)
107 {
108  TPointerOffsetType offset = INT_MAX;
109  for ( CItemsInfo::CIterator i(items); i.Valid(); ++i ) {
110  const CItemInfo* itemInfo = items.GetItemInfo(i);
111  offset = min(offset, itemInfo->GetOffset());
112  }
113  return offset;
114 }
115 
117 {
118 public:
120 
121  static const CSequenceOfTypeInfo* GetType(const TIterator& iter)
122  {
124  }
125  static bool InitIterator(TIterator& iter)
126  {
127  TObjectPtr nodePtr =
128  GetType(iter)->FirstNode(iter.GetContainerPtr());
129  iter.m_IteratorData = nodePtr;
130  return nodePtr != 0;
131  }
132  static void ReleaseIterator(TIterator& )
133  {
134  }
135  static void CopyIterator(TIterator& dst,
136  const TIterator& src)
137  {
138  dst.m_IteratorData = src.m_IteratorData;
139  }
140  static bool NextElement(TIterator& iter)
141  {
142  TObjectPtr nodePtr = GetType(iter)->NextNode(iter.m_IteratorData);
143  iter.m_IteratorData = nodePtr;
144  return nodePtr != 0;
145  }
147  {
148  return GetType(iter)->Data(iter.m_IteratorData);
149  }
150 };
151 
153 {
154 public:
156 
157  static const CSequenceOfTypeInfo* GetType(const TIterator& iter)
158  {
160  }
161  static bool InitIterator(TIterator& iter)
162  {
163  TObjectPtr* nodePtrPtr =
164  &GetType(iter)->FirstNode(iter.GetContainerPtr());
165  iter.m_IteratorData = nodePtrPtr;
166  return *nodePtrPtr != 0;
167  }
168  static void ReleaseIterator(TIterator& )
169  {
170  }
171  static void CopyIterator(TIterator& dst, const TIterator& src)
172  {
173  dst.m_IteratorData = src.m_IteratorData;
174  }
175  static bool NextElement(TIterator& iter)
176  {
177  TObjectPtr* nodePtrPtr =
178  &GetType(iter)->NextNode(*(TObjectPtr*)iter.m_IteratorData);
179  iter.m_IteratorData = nodePtrPtr;
180  return *nodePtrPtr != 0;
181  }
182  static TObjectPtr GetElementPtr(const TIterator& iter)
183  {
184  return GetType(iter)->Data(*(TObjectPtr*)iter.m_IteratorData);
185  }
186  static bool EraseElement(TIterator& iter)
187  {
188  const CSequenceOfTypeInfo* type = GetType(iter);
189 
190  TObjectPtr* nodePtrPtr = (TObjectPtr*)iter.m_IteratorData;
191  TObjectPtr nodePtr = *nodePtrPtr;
192  TObjectPtr nextNodePtr = type->NextNode(nodePtr);
193  *nodePtrPtr = nextNodePtr;
194  type->DeleteNode(nodePtr);
195  return nextNodePtr != 0;
196  }
197  static void EraseAllElements(TIterator& iter)
198  {
199  const CSequenceOfTypeInfo* type = GetType(iter);
200 
201  TObjectPtr* nodePtrPtr = (TObjectPtr*)iter.m_IteratorData;
202  TObjectPtr nodePtr = *nodePtrPtr;
203  *nodePtrPtr = 0;
204  while ( nodePtr ) {
205  TObjectPtr nextNodePtr = type->NextNode(nodePtr);
206  type->DeleteNode(nodePtr);
207  nodePtr = nextNodePtr;
208  }
209  }
210 };
211 
213 {
214 public:
216  TTypeInfo containerType,
217  TObjectPtr containerPtr)
218  {
219  const CSequenceOfTypeInfo* seqType =
221 
222  BEGIN_OBJECT_FRAME_OF2(in, eFrameArray, seqType);
223  in.BeginContainer(seqType);
224 
225  TTypeInfo elementType = seqType->GetElementType();
226  BEGIN_OBJECT_FRAME_OF2(in, eFrameArrayElement, elementType);
227 
228  TObjectPtr* nextNodePtr = &seqType->FirstNode(containerPtr);
229 
230  while ( in.BeginContainerElement(elementType) ) {
231  // get current node pointer
232  TObjectPtr node = *nextNodePtr;
233 
234  // create node
235  _ASSERT(!node);
236  node = *nextNodePtr = seqType->CreateNode();
237 
238  // read node data
239  in.ReadObject(seqType->Data(node), elementType);
240 
241  // save next node for next read
242  nextNodePtr = &seqType->NextNode(node);
243 
244  in.EndContainerElement();
245  }
246 
248 
249  in.EndContainer();
251  }
252 };
253 
255 {
257  const CAutoPointerTypeInfo* ptrInfo =
258  dynamic_cast<const CAutoPointerTypeInfo*>(type);
259  if ( ptrInfo != 0 ) {
260  // data type is auto_ptr
261  TTypeInfo asnType = ptrInfo->GetPointedType();
262  if ( asnType->GetTypeFamily() == eTypeFamilyChoice ) {
263  // CHOICE
264  SetChoiceNext();
265  m_ElementType = asnType;
266  }
267  else if ( asnType->GetTypeFamily() == eTypeFamilyClass ) {
268  // user types
269  const CClassTypeInfo* classType =
271  if ( GetFirstItemOffset(classType->GetItems()) < sizeof(void*) ) {
273  msg << "CSequenceOfTypeInfo: incompatible type: " <<
274  type->GetName() << ": " << typeid(*type).name() <<
275  " size: " << type->GetSize();
277  }
278  m_NextOffset = 0;
279  m_DataOffset = 0;
280  m_ElementType = asnType;
281  }
282  else if ( asnType->GetSize() <= sizeof(dataval) ) {
283  // standard types and SET/SEQUENCE OF
284  SetValNodeNext();
285  m_ElementType = asnType;
286  }
287  else {
288 /*
289  _ASSERT(type->GetSize() <= sizeof(dataval));
290  SetValNodeNext();
291 */
293  msg << "CSequenceOfTypeInfo: incompatible type: " <<
294  type->GetName() << ": " << typeid(*type).name() <<
295  " size: " << type->GetSize();
297  }
298  }
299  else if ( type->GetSize() <= sizeof(dataval) ) {
300  // SEQUENCE OF, SET OF or primitive types
301  SetValNodeNext();
302  }
303  else {
305  msg << "CSequenceOfTypeInfo: incompatible type: " <<
306  type->GetName() << ": " << typeid(*type).name() <<
307  " size: " << type->GetSize();
309  }
310 
311  {
313  SetReadFunction(&TFunc::ReadSequence);
314  }
315  {
317  SetConstIteratorFunctions(&TFunc::InitIterator, &TFunc::ReleaseIterator,
318  &TFunc::CopyIterator, &TFunc::NextElement,
319  &TFunc::GetElementPtr);
320  }
321  {
323  SetIteratorFunctions(&TFunc::InitIterator, &TFunc::ReleaseIterator,
324  &TFunc::CopyIterator, &TFunc::NextElement,
325  &TFunc::GetElementPtr,
326  &TFunc::EraseElement, &TFunc::EraseAllElements);
327  }
328 }
329 
331 {
332  m_NextOffset = offsetof(valnode, next);
333  m_DataOffset = 0;
334 }
335 
337 {
338  m_NextOffset = offsetof(valnode, next);
339  m_DataOffset = offsetof(valnode, data);
340 }
341 
343 {
344  if ( m_DataOffset == 0 ) {
345  _ASSERT(m_NextOffset == 0 || m_NextOffset == offsetof(valnode, next));
346  return GetElementType()->Create();
347  }
348  else {
349  _ASSERT(m_NextOffset == offsetof(valnode, next));
350  _ASSERT(m_DataOffset == offsetof(valnode, data));
351  return Alloc(sizeof(valnode));
352  }
353 }
354 
356 {
357  if ( m_DataOffset == 0 ) {
358  _ASSERT(m_NextOffset == 0 || m_NextOffset == offsetof(valnode, next));
359  GetElementType()->Delete(node);
360  }
361  else {
362  _ASSERT(m_NextOffset == offsetof(valnode, next));
363  _ASSERT(m_DataOffset == offsetof(valnode, data));
364  Free(node);
365  }
366 }
367 
369 {
370  return FirstNode(object) == 0;
371 }
372 
374 {
375  FirstNode(dst) = 0;
376 }
377 
379  ESerialRecursionMode how) const
380 {
381  src = FirstNode(src);
382  if ( src == 0 ) {
383  FirstNode(dst) = 0;
384  return;
385  }
386 
387  TTypeInfo dataType = GetElementType();
388  dst = FirstNode(dst) = CreateNode();
389  dataType->Assign(Data(dst), Data(src), how);
390  while ( (src = NextNode(src)) != 0 ) {
391  dst = NextNode(dst) = CreateNode();
392  dataType->Assign(Data(dst), Data(src), how);
393  }
394 }
395 
396 
398 
400 {
401  return s_SetOfTypeInfo_map->GetTypeInfo(base, &CreateTypeInfo);
402 }
403 
405 {
406  return new CSetOfTypeInfo(base);
407 }
408 
410  : CParent(type, true)
411 {
412 }
413 
415  : CParent(name, type, true)
416 {
417 }
418 
420  : CParent(name, type, true)
421 {
422 }
423 
426 {
431 }
432 
434 {
435  return Get(object)->totlen == 0;
436 }
437 
439  ESerialRecursionMode) const
440 {
441  bytestore* bs1 = Get(obj1);
442  bytestore* bs2 = Get(obj2);
443  if ( bs1 == 0 || bs2 == 0 )
444  return bs1 == bs2;
445 
446  Int4 len = BSLen(bs1);
447  if ( len != BSLen(bs2) )
448  return false;
449 
450  BSSeek(bs1, 0, SEEK_SET);
451  BSSeek(bs2, 0, SEEK_SET);
452  char buff1[1024], buff2[1024];
453  while ( len > 0 ) {
454  Int4 chunk = Int4(sizeof(buff1));
455  if ( chunk > len )
456  chunk = len;
457  BSRead(bs1, buff1, chunk);
458  BSRead(bs2, buff2, chunk);
459  if ( memcmp(buff1, buff2, chunk) != 0 )
460  return false;
461  len -= chunk;
462  }
463  return true;
464 }
465 
467 {
468  BSFree(Get(dst));
469  Get(dst) = BSNew(0);
470 }
471 
473  ESerialRecursionMode) const
474 {
475  if ( Get(src) == 0 ) {
476  NCBI_THROW(CSerialException,eInvalidData, "null bytestore pointer");
477  }
478  BSFree(Get(dst));
479  Get(dst) = BSDup(Get(src));
480 }
481 
483  TTypeInfo /*objectType*/,
484  TObjectPtr objectPtr)
485 {
487  BSFree(Get(objectPtr));
488  char buffer[1024];
489  Int4 count = Int4(block.Read(buffer, sizeof(buffer)));
490  bytestore* bs = Get(objectPtr) = BSNew(count);
491  BSWrite(bs, buffer, count);
492  while ( (count = Int4(block.Read(buffer, sizeof(buffer)))) != 0 ) {
493  BSWrite(bs, buffer, count);
494  }
495  block.End();
496 }
497 
499  TTypeInfo /*objectType*/,
500  TConstObjectPtr objectPtr)
501 {
502  bytestore* bs = const_cast<bytestore*>(Get(objectPtr));
503  if ( bs == 0 )
504  out.ThrowError(out.fIllegalCall, "null bytestore pointer");
505  Int4 len = BSLen(bs);
507  BSSeek(bs, 0, SEEK_SET);
508  char buff[1024];
509  while ( len > 0 ) {
510  Int4 chunk = Int4(sizeof(buff));
511  if ( chunk > len )
512  chunk = len;
513  BSRead(bs, buff, chunk);
514  block.Write(buff, chunk);
515  len -= chunk;
516  }
517  block.End();
518 }
519 
521  TTypeInfo /*objectType*/)
522 {
523  copier.CopyByteBlock();
524 }
525 
527  TTypeInfo /*objectType*/)
528 {
529  in.SkipByteBlock();
530 }
531 
533  vector<char>& value) const
534 {
535  bytestore* bs = const_cast<bytestore*>(Get(objectPtr));
536  if ( bs == 0 ) {
537  NCBI_THROW(CSerialException,eInvalidData, "null bytestore pointer");
538  }
539  Int4 len = BSLen(bs);
540  value.resize(len);
541  BSSeek(bs, 0, SEEK_SET);
542  BSRead(bs, &value.front(), len);
543 }
544 
546  const vector<char>& value) const
547 {
548  Int4 count = Int4(value.size());
549  bytestore* bs = Get(objectPtr) = BSNew(count);
550  BSWrite(bs, const_cast<char*>(&value.front()), count);
551 }
552 
554 {
555  static TTypeInfo typeInfo = 0;
556  if ( !typeInfo )
557  typeInfo = new COctetStringTypeInfo();
558  return typeInfo;
559 }
560 
562  TAsnNewProc newProc,
563  TAsnFreeProc freeProc,
564  TAsnReadProc readProc,
565  TAsnWriteProc writeProc)
566  : CParent(sizeof(TObjectType), name, ePrimitiveValueSpecial),
567  m_NewProc(newProc), m_FreeProc(freeProc),
568  m_ReadProc(readProc), m_WriteProc(writeProc)
569 {
572 }
573 
575  TAsnNewProc newProc,
576  TAsnFreeProc freeProc,
577  TAsnReadProc readProc,
578  TAsnWriteProc writeProc)
579  : CParent(sizeof(TObjectType), name, ePrimitiveValueSpecial),
580  m_NewProc(newProc), m_FreeProc(freeProc),
581  m_ReadProc(readProc), m_WriteProc(writeProc)
582 {
585 }
586 
588 {
589  return Get(object) == 0;
590 }
591 
593  ESerialRecursionMode) const
594 {
595  return Get(object1) == 0 && Get(object2) == 0;
596 }
597 
599 {
600  Get(dst) = 0;
601 }
602 
604  ESerialRecursionMode ) const
605 {
606  NCBI_THROW(CSerialException,eInvalidData, "cannot assign non default value");
607 }
608 
610  TTypeInfo objectType,
611  TObjectPtr objectPtr)
612 {
613  const COldAsnTypeInfo* oldAsnType =
615 
616  CObjectIStream::AsnIo io(in, oldAsnType->GetName());
617  if ( (Get(objectPtr) = oldAsnType->m_ReadProc(io, 0)) == 0 )
618  in.ThrowError(in.fFail, "read fault");
619  io.End();
620 }
621 
623  TTypeInfo objectType,
624  TConstObjectPtr objectPtr)
625 {
626  const COldAsnTypeInfo* oldAsnType =
628 
629  CObjectOStream::AsnIo io(out, oldAsnType->GetName());
630  if ( !oldAsnType->m_WriteProc(Get(objectPtr), io, 0) )
631  out.ThrowError(out.fFail, "write fault");
632  io.End();
633 }
634 
635 // CObjectOStream, CObjectIStream, and corresponding AsnIo
636 
637 extern "C" {
639  {
640  if ( !object || !data )
641  return -1;
642 
643  static_cast<CObjectOStream::AsnIo*>(object)->Write(data, length);
644  return length;
645  }
646 
648  {
649  if ( !object || !data )
650  return -1;
651  CObjectIStream::AsnIo* asnio =
652  static_cast<CObjectIStream::AsnIo*>(object);
653  return Uint2(asnio->Read(data, length));
654  }
655 }
656 
657 CObjectOStream::AsnIo::AsnIo(CObjectOStream& out, const string& rootTypeName)
658  : m_Stream(out), m_RootTypeName(rootTypeName), m_Ended(false), m_Count(0)
659 {
660  Int1 flags = ASNIO_OUT;
661  ESerialDataFormat format = out.GetDataFormat();
662  if ( format == eSerial_AsnText )
663  flags |= ASNIO_TEXT;
664  else if ( format == eSerial_AsnBinary )
665  flags |= ASNIO_BIN;
666  else
667  out.ThrowError(out.fIllegalCall,
668  "incompatible stream format - must be ASN.1 (text or binary)");
669  m_AsnIo = AsnIoNew(flags, 0, this, 0, WriteAsn);
670  if ( format == eSerial_AsnText ) {
671  // adjust indent level and buffer
672  size_t indent = out.m_Output.GetIndentLevel();
673  m_AsnIo->indent_level = Int1(indent);
674  size_t max_indent = m_AsnIo->max_indent;
675  if ( indent >= max_indent ) {
676  Boolean* tmp = m_AsnIo->first;
677  m_AsnIo->first = (BoolPtr) MemNew((sizeof(Boolean) * (indent + 10)));
678  MemCopy(m_AsnIo->first, tmp, (size_t)(sizeof(Boolean) * max_indent));
679  MemFree(tmp);
680  m_AsnIo->max_indent = Int1(indent);
681  }
682  }
683 }
684 
686 {
687  _ASSERT(!m_Ended);
688  if ( GetStream().InGoodState() ) {
689  AsnIoClose(*this);
690  m_Ended = true;
691  }
692 }
693 
695 {
696  if ( !m_Ended ) {
697  try {
698  GetStream().Unended("AsnIo write error");
699  }
700  catch (...) {
701  ERR_POST_X(1, "AsnIo write error");
702  }
703  }
704 }
705 
707 {
708  return m_Stream;
709 }
710 
711 CObjectOStream::AsnIo::operator asnio*(void)
712 {
713  return m_AsnIo;
714 }
715 
717 {
718  return m_AsnIo;
719 }
720 
721 const string& CObjectOStream::AsnIo::GetRootTypeName(void) const
722 {
723  return m_RootTypeName;
724 }
725 
726 void CObjectOStream::AsnIo::Write(const char* data, size_t length)
727 {
728  if ( GetStream().GetDataFormat() == eSerial_AsnText ) {
729  if ( m_Count == 0 ) {
730  // dirty hack to skip structure name with '::='
731  const char* p = (const char*)memchr(data, ':', length);
732  if ( p && p[1] == ':' && p[2] == '=' ) {
733  // check type name
734  const char* beg = data;
735  const char* end = p;
736  while ( beg < end && isspace((unsigned char) beg[0]) )
737  beg++;
738  while ( end > beg && isspace((unsigned char) end[-1]) )
739  end--;
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() << "\"");
744  }
745  // skip header
746  size_t skip = p + 3 - data;
747  _TRACE(Warning <<
748  "AsnWrite: skipping \"" << string(data, skip) << "\"");
749  data += skip;
750  length -= skip;
751  }
752  else {
753  ERR_POST_X(3, "AsnWrite: no \"Asn-Type ::=\" header (data=\""
754  << data << "\")");
755  }
756  m_Count = 1;
757  }
758  GetStream().m_Output.PutString(data, length);
759  }
760  else {
761  if ( length == 0 )
762  return;
764  static_cast<CObjectOStreamAsnBinary&>(GetStream());
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);
773  out.m_CurrentPosition += CNcbiStreamoff(length);
774 #endif
775  out.m_Output.PutString(data, length);
776  }
777 }
778 
779 CObjectIStream::AsnIo::AsnIo(CObjectIStream& in, const string& rootTypeName)
780  : m_Stream(in), m_Ended(false),
781  m_RootTypeName(rootTypeName), m_Count(0)
782 {
783  Int1 flags = ASNIO_IN;
784  ESerialDataFormat format = in.GetDataFormat();
785  if ( format == eSerial_AsnText )
786  flags |= ASNIO_TEXT;
787  else if ( format == eSerial_AsnBinary )
788  flags |= ASNIO_BIN;
789  else
790  in.ThrowError(in.fIllegalCall,
791  "incompatible stream format - must be ASN.1 (text or binary)");
792  m_AsnIo = AsnIoNew(flags, 0, this, ReadAsn, 0);
793  if ( format == eSerial_AsnBinary ) {
794 #if CHECK_STREAM_INTEGRITY
796  static_cast<CObjectIStreamAsnBinary&>(in);
797  if ( sin.m_CurrentTagState != sin.eTagStart ) {
798  in.ThrowError(in.fIllegalCall,
799  string("double tag read: rootTypeName= ")+ rootTypeName);
800  }
801 #endif
802  }
803 }
804 
806 {
807  _ASSERT(!m_Ended);
808  if ( GetStream().InGoodState() ) {
809  AsnIoClose(*this);
810  m_Ended = true;
811  }
812 }
813 
815 {
816  if ( !m_Ended )
817  GetStream().Unended("AsnIo read error");
818 }
819 
821 {
822  return m_Stream;
823 }
824 
825 CObjectIStream::AsnIo::operator asnio*(void)
826 {
827  return m_AsnIo;
828 }
829 
831 {
832  return m_AsnIo;
833 }
834 
835 const string& CObjectIStream::AsnIo::GetRootTypeName(void) const
836 {
837  return m_RootTypeName;
838 }
839 
840 size_t CObjectIStream::AsnIo::Read(char* data, size_t length)
841 {
842  if ( GetStream().GetDataFormat() == eSerial_AsnText ) {
843  size_t count = 0;
844  if ( m_Count == 0 ) {
845  // dirty hack to add structure name with '::='
846  const string& name = GetRootTypeName();
847  SIZE_TYPE nameLength = name.size();
848  count = nameLength + 3;
849  if ( length < count ) {
850  GetStream().ThrowError(GetStream().fFail,
851  string("buffer too small to put structure name in: name= ")
852  + name);
853  }
854  memcpy(data, name.data(), nameLength);
855  data[nameLength] = ':';
856  data[nameLength + 1] = ':';
857  data[nameLength + 2] = '=';
858  data += count;
859  length -= count;
860  m_Count = 1;
861  }
862  return count + GetStream().m_Input.ReadLine(data, length);
863  }
864  else {
865  *data = GetStream().m_Input.GetChar();
866  return 1;
867  }
868 }
869 
871 
872 #endif
CAliasTypeInfoFunctions TFunc
Definition: aliasinfo.cpp:59
Int2 LIBCALLBACK ReadAsn(Pointer object, CharPtr data, Uint2 length)
Definition: asntypes.cpp:647
static CSafeStatic< CTypeInfoMap > s_SequenceOfTypeInfo_map
Definition: asntypes.cpp:72
static size_t GetFirstItemOffset(const CItemsInfo &items)
Definition: asntypes.cpp:106
Int2 LIBCALLBACK WriteAsn(Pointer object, CharPtr data, Uint2 length)
Definition: asntypes.cpp:638
static CSafeStatic< CTypeInfoMap > s_SetOfTypeInfo_map
Definition: asntypes.cpp:397
static void * Alloc(size_t size)
Definition: asntypes.cpp:59
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStreamAsnBinary –.
Definition: objostrasnb.hpp:58
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CSafeStatic<>::
static bool NextElement(TIterator &iter)
Definition: asntypes.cpp:140
CContainerTypeInfo::CConstIterator TIterator
Definition: asntypes.cpp:119
static void ReleaseIterator(TIterator &)
Definition: asntypes.cpp:132
static void CopyIterator(TIterator &dst, const TIterator &src)
Definition: asntypes.cpp:135
static TConstObjectPtr GetElementPtr(const TIterator &iter)
Definition: asntypes.cpp:146
static bool InitIterator(TIterator &iter)
Definition: asntypes.cpp:125
static const CSequenceOfTypeInfo * GetType(const TIterator &iter)
Definition: asntypes.cpp:121
static void CopyIterator(TIterator &dst, const TIterator &src)
Definition: asntypes.cpp:171
static const CSequenceOfTypeInfo * GetType(const TIterator &iter)
Definition: asntypes.cpp:157
CContainerTypeInfo::CIterator TIterator
Definition: asntypes.cpp:155
static TObjectPtr GetElementPtr(const TIterator &iter)
Definition: asntypes.cpp:182
static bool InitIterator(TIterator &iter)
Definition: asntypes.cpp:161
static bool EraseElement(TIterator &iter)
Definition: asntypes.cpp:186
static void EraseAllElements(TIterator &iter)
Definition: asntypes.cpp:197
static void ReleaseIterator(TIterator &)
Definition: asntypes.cpp:168
static bool NextElement(TIterator &iter)
Definition: asntypes.cpp:175
static void ReadSequence(CObjectIStream &in, TTypeInfo containerType, TObjectPtr containerPtr)
Definition: asntypes.cpp:215
Root class for all serialization exceptions.
Definition: exception.hpp:50
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.
static uch flags
#define T(s)
Definition: common.h:230
std::ofstream out("events_result.xml")
main entry point for tests
void MemFree(char *p)
Definition: ftacpp.hpp:55
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:56
static int type
Definition: getdata.c:31
static char tmp[3200]
Definition: utf8.c:42
int offset
Definition: replacements.h:160
char data[12]
Definition: iconv.c:80
#define BoolPtr
Definition: ncbistd.hpp:137
#define CharPtr
Definition: ncbistd.hpp:125
#define MemCopy
Definition: ncbimem.hpp:148
#define MemNew(x)
Definition: ncbimem.hpp:143
#define LIBCALLBACK
Definition: ncbistd.hpp:302
#define Pointer
Definition: ncbistd.hpp:114
#define Free
Definition: ncbimem.hpp:122
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
const CItemInfo * GetItemInfo(TMemberIndex index) const
TPointerOffsetType GetOffset(void) const
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
void * TObjectPtr
Definition: serialdef.hpp:55
const void * TConstObjectPtr
Definition: serialdef.hpp:59
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:55
ssize_t TPointerOffsetType
Definition: serialdef.hpp:241
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
@ ePrimitiveValueSpecial
null, void
Definition: serialdef.hpp:148
@ ePrimitiveValueOctetString
vector<(signed|unsigned)? char>
Definition: serialdef.hpp:155
@ eTypeFamilyClass
Definition: serialdef.hpp:140
@ eTypeFamilyChoice
Definition: serialdef.hpp:141
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
ESerialDataFormat GetDataFormat(void) const
Get data format.
AsnIo(CObjectIStream &in, const string &rootTypeName)
Definition: asntypes.cpp:779
CObjectOStream & GetStream(void) const
Definition: asntypes.cpp:706
const string & GetRootTypeName(void) const
Definition: asntypes.cpp:721
size_t Read(char *data, size_t length)
Definition: asntypes.cpp:840
asnio * operator->(void)
Definition: asntypes.cpp:830
void Write(const void *bytes, size_t length)
void Write(const char *data, size_t length)
Definition: asntypes.cpp:726
const string & GetRootTypeName(void) const
Definition: asntypes.cpp:835
void CopyByteBlock(void)
Definition: objcopy.cpp:191
#define BEGIN_OBJECT_FRAME_OF2(Stream, Type, Arg)
Definition: objstack.hpp:219
bool InGoodState(void)
Check fail flags and also the state of input data source.
Definition: objistr.cpp:570
CObjectIStream & GetStream(void) const
Definition: asntypes.cpp:820
bool InGoodState(void)
Check fail flags and also the state of output stream.
Definition: objostr.cpp:386
ESerialDataFormat GetDataFormat(void) const
Get data format.
asnio * operator->(void)
Definition: asntypes.cpp:716
#define END_OBJECT_FRAME_OF(Stream)
Definition: objstack.hpp:201
AsnIo(CObjectOStream &out, const string &rootTypeName)
Definition: asntypes.cpp:657
size_t Read(void *dst, size_t length, bool forceLength=false)
Definition: objistr.cpp:1576
@ fFail
Internal error, the real reason is unclear.
Definition: objistr.hpp:385
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
int8_t Int1
1-byte (8-bit) signed integer
Definition: ncbitype.h:98
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::streamoff CNcbiStreamoff
Portable alias for streamoff.
Definition: ncbistre.hpp:137
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
void SetWriteFunction(TTypeWriteFunction func)
Definition: typeinfo.cpp:487
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
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
CTypeRef m_ElementType
Definition: continfo.hpp:185
const CContainerTypeInfo * GetContainerType(void) const
void SetConstIteratorFunctions(TInitIteratorConst, TReleaseIteratorConst, TCopyIteratorConst, TNextElementConst, TGetElementPtrConst)
Definition: continfo.cpp:171
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const =0
Set object to copy of another one.
void SetSkipFunction(TTypeSkipFunction func)
Definition: typeinfo.cpp:497
void SetCopyFunction(TTypeCopyFunction func)
Definition: typeinfo.cpp:492
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.
Definition: typeinfo.cpp:299
void SetIteratorFunctions(TInitIterator, TReleaseIterator, TCopyIterator, TNextElement, TGetElementPtr, TEraseElement, TEraseAllElements)
Definition: continfo.cpp:184
void SetReadFunction(TTypeReadFunction func)
Definition: typeinfo.cpp:477
TAsnReadProc m_ReadProc
Definition: asntypes.hpp:226
static TObjectPtr & FirstNode(TObjectPtr object)
Definition: asntypes.hpp:79
static TObjectType & Get(TObjectPtr object)
Definition: asntypes.hpp:198
COldAsnTypeInfo(const char *name, TAsnNewProc newProc, TAsnFreeProc freeProc, TAsnReadProc readProc, TAsnWriteProc writeProc)
Definition: asntypes.cpp:561
TObjectPtr(* TAsnFreeProc)(TObjectPtr)
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
Definition: asntypes.cpp:592
static void CopyOctetString(CObjectStreamCopier &copier, TTypeInfo objectType)
Definition: asntypes.cpp:520
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const
Set object to copy of another one.
Definition: asntypes.cpp:378
static void WriteOctetString(CObjectOStream &out, TTypeInfo objectType, TConstObjectPtr objectPtr)
Definition: asntypes.cpp:498
static void ReadOctetString(CObjectIStream &in, TTypeInfo objectType, TObjectPtr objectPtr)
Definition: asntypes.cpp:482
bytestore * TObjectType
Definition: asntypes.hpp:145
static TTypeInfo GetTypeInfo(void)
Definition: asntypes.cpp:553
CSetOfTypeInfo(TTypeInfo type)
Definition: asntypes.cpp:409
TObjectPtr(* TAsnNewProc)(void)
static TObjectType & Get(TObjectPtr object)
Definition: asntypes.hpp:149
virtual void SetDefault(TObjectPtr dst) const
Set object to default value.
Definition: asntypes.cpp:373
virtual void SetValueOctetString(TObjectPtr objectPtr, const vector< char > &value) const
Definition: asntypes.cpp:545
static void ReadOldAsnStruct(CObjectIStream &in, TTypeInfo objectType, TObjectPtr objectPtr)
Definition: asntypes.cpp:609
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const
Set object to copy of another one.
Definition: asntypes.cpp:603
unsigned char(* TAsnWriteProc)(TObjectPtr, asnio *, asntype *)
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const
Set object to copy of another one.
Definition: asntypes.cpp:472
virtual bool IsDefault(TConstObjectPtr object) const
Check, whether the object contains default value.
Definition: asntypes.cpp:587
void InitSequenceOfTypeInfo(void)
Definition: asntypes.cpp:254
CSequenceOfTypeInfo(TTypeInfo type, bool randomOrder=false)
Definition: asntypes.cpp:85
TObjectPtr TObjectType
Definition: asntypes.hpp:62
TObjectPtr(* TAsnReadProc)(asnio *, asntype *)
virtual bool IsDefault(TConstObjectPtr object) const
Check, whether the object contains default value.
Definition: asntypes.cpp:433
static TTypeInfo GetTypeInfo(TTypeInfo base)
Definition: asntypes.cpp:399
TAsnWriteProc m_WriteProc
Definition: asntypes.hpp:227
void * TObjectType
Definition: asntypes.hpp:189
static void SkipOctetString(CObjectIStream &in, TTypeInfo objectType)
Definition: asntypes.cpp:526
static TTypeInfo GetTypeInfo(TTypeInfo base)
Definition: asntypes.cpp:75
void SetValNodeNext(void)
Definition: asntypes.cpp:336
static void WriteOldAsnStruct(CObjectOStream &out, TTypeInfo objectType, TConstObjectPtr objectPtr)
Definition: asntypes.cpp:622
virtual bool IsDefault(TConstObjectPtr object) const
Check, whether the object contains default value.
Definition: asntypes.cpp:368
virtual void SetDefault(TObjectPtr dst) const
Set object to default value.
Definition: asntypes.cpp:598
virtual void SetDefault(TObjectPtr dst) const
Set object to default value.
Definition: asntypes.cpp:466
virtual bool Equals(TConstObjectPtr obj1, TConstObjectPtr obj2, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
Definition: asntypes.cpp:438
void DeleteNode(TObjectPtr node) const
Definition: asntypes.cpp:355
TObjectPtr CreateNode(void) const
Definition: asntypes.cpp:342
static CTypeInfo * CreateTypeInfo(TTypeInfo base)
Definition: asntypes.cpp:80
void SetChoiceNext(void)
Definition: asntypes.cpp:330
TObjectPtr Data(TObjectPtr object) const
Definition: asntypes.hpp:97
static CTypeInfo * CreateTypeInfo(TTypeInfo base)
Definition: asntypes.cpp:404
virtual void GetValueOctetString(TConstObjectPtr objectPtr, vector< char > &value) const
Definition: asntypes.cpp:532
TObjectPtr & NextNode(TObjectPtr object) const
Definition: asntypes.hpp:87
X * NotNull(X *object)
Check for not null value (after C malloc, strdup etc.).
Definition: ncbiutil.hpp:85
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)
int i
int len
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Static variables safety - create on demand, destroy on application termination.
#define offsetof(T, F)
Definition: ncbi_socket.c:700
Uint1 Boolean
bool replacment for C
Definition: ncbi_std.h:94
int isspace(Uchar c)
Definition: ncbictype.hpp:69
Useful/utility classes and methods.
T min(T x_, T y_)
static Format format
Definition: njn_ioutil.cpp:53
std::istream & in(std::istream &in_, double &x_)
#define count
static uint8_t * buffer
Definition: pcre2test.c:1016
string indent(" ")
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Definition: type.c:6
const char * name
Definition: type.c:8
#define _ASSERT
#define SEEK_SET
Definition: zconf.h:500
voidp calloc(uInt items, uInt size)
Modified on Fri Sep 20 14:58:11 2024 by modify_doxy.py rev. 669887