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

Go to the SVN repository for this file.

1 /* $Id: objostrjson.cpp 95477 2021-11-18 14:56:01Z 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: Andrei Gourianov
27 *
28 * File Description:
29 * JSON object output stream
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/ncbi_limits.h>
36 
37 #include <serial/objostrjson.hpp>
38 #include <serial/objistr.hpp>
39 #include <serial/objcopy.hpp>
40 #include <serial/impl/memberid.hpp>
42 #include <serial/enumvalues.hpp>
43 #include <serial/objhook.hpp>
45 #include <serial/impl/choice.hpp>
46 #include <serial/impl/continfo.hpp>
47 #include <serial/delaybuf.hpp>
48 #include <serial/impl/ptrinfo.hpp>
49 #include <serial/error_codes.hpp>
50 
51 #include <stdio.h>
52 #include <math.h>
53 
54 
55 #define NCBI_USE_ERRCODE_X Serial_OStream
56 
58 
59 
61  EOwnership deleteOut)
62 {
63  return new CObjectOStreamJson(out, deleteOut);
64 }
65 
66 
67 
70  m_FileHeader(false),
71  m_BlockStart(false),
72  m_ExpectValue(false),
73  m_PreserveKeys(false),
74  m_StringEncoding(eEncoding_UTF8),
75  m_BinaryFormat(eDefault),
76  m_WrapAt(0)
77 {
80 }
81 
83  : CObjectOStream(eSerial_Json, out, deleteOut),
84  m_FileHeader(false),
85  m_BlockStart(false),
86  m_ExpectValue(false),
87  m_PreserveKeys(false),
88  m_StringEncoding(eEncoding_UTF8),
89  m_BinaryFormat(eDefault),
90  m_WrapAt(0)
91 {
94 }
95 
97 {
98 }
99 
101 {
102  m_StringEncoding = enc;
103 }
104 
106 {
107  return m_StringEncoding;
108 }
109 
112 {
113  return m_BinaryFormat;
114 }
116 {
117  m_BinaryFormat = fmt;
118 }
119 
120 void CObjectOStreamJson::SetJsonpMode(const string& function_name)
121 {
122  m_JsonpPrefix = function_name + "(";
123  m_JsonpSuffix = ");";
124 }
125 
127 {
128  if (prefix) {*prefix = m_JsonpPrefix;}
129  if (suffix) {*suffix = m_JsonpSuffix;}
130 }
131 
133 {
134  return "line "+NStr::SizetToString(m_Output.GetLine());
135 }
136 
138 {
139  if (!m_JsonpPrefix.empty() || !m_JsonpSuffix.empty()) {
141  }
142  if (type->GetDataSpec() != EDataSpec::eJSON) {
143  m_FileHeader = true;
144  StartBlock();
145  if (!type->GetName().empty()) {
146  m_Output.PutEol();
147  WriteKey(type->GetName());
148  }
149  }
150 }
151 
153 {
154  if (m_FileHeader) {
155  EndBlock();
156  m_FileHeader = false;
157  } else {
158  m_BlockStart = false;
159  m_ExpectValue = false;
160  }
161  if (!m_JsonpPrefix.empty() || !m_JsonpSuffix.empty()) {
163  }
164  m_Output.PutEol();
166 }
167 
169 {
170  WriteKeywordValue( data ? "true" : "false");
171 }
172 
174 {
175  string s;
176  s += data;
177  WriteString(s);
178 }
179 
181 {
183 }
184 
186 {
188 }
189 
191 {
193 }
194 
196 {
198 }
199 
201 {
202  WriteDouble2(data,FLT_DIG);
203 }
204 
206 {
207  WriteDouble2(data,DBL_DIG);
208 }
209 
210 void CObjectOStreamJson::WriteDouble2(double data, unsigned digits)
211 {
212  if (isnan(data)) {
213  ThrowError(fInvalidData, "invalid double: not a number");
214  }
215  if (!finite(data)) {
216  ThrowError(fInvalidData, "invalid double: infinite");
217  }
218  if (m_FastWriteDouble) {
219  char buffer[64];
220  WriteKeywordValue( string(buffer,
221  NStr::DoubleToStringPosix(data, digits, buffer, sizeof(buffer))));
222  } else {
224  }
225 }
226 
228 {
229  WriteValue(str);
230 }
231 
234 {
236 }
237 
239 {
240  WriteString(s);
241 }
242 
245 {
246  string s;
247  in.ReadString(s, type);
248  WriteString(s, type);
249 }
250 
252 {
253  string s;
254  in.ReadStringStore(s);
255  WriteStringStore(s);
256 }
257 
259 {
261  if (m_ExpectValue ||
265  WriteKeywordValue("null");
266  }
267 }
268 
270 {
271  ThrowError(fNotImplemented, "Not Implemented");
272 }
273 
275 {
276  ThrowError(fNotImplemented, "Not Implemented");
277 }
278 
280 {
281  ThrowError(fNotImplemented, "Not Implemented");
282 }
283 
285 {
286  ThrowError(fNotImplemented, "Not Implemented");
287 }
288 
290 {
291  if (!m_ExpectValue && !m_SkippedMemberId.empty()) {
292  m_SkippedMemberId.erase();
293  }
294  if (m_ExpectValue) {
295  WriteKeywordValue("null");
296  }
297 }
298 
300 {
301  string obj_name = obj.GetName();
302  if (obj_name.empty()) {
303  if (!StackIsEmpty() && TopFrame().HasMemberId()) {
304  obj_name = TopFrame().GetMemberId().GetName();
305  }
306  if (obj_name.empty()) {
307  ThrowError(fInvalidData, "AnyContent object must have name");
308  }
309  }
310  WriteKey(obj_name);
311  const vector<CSerialAttribInfoItem>& attlist = obj.GetAttributes();
312  if (attlist.empty()) {
314  return;
315  }
316  StartBlock();
317  vector<CSerialAttribInfoItem>::const_iterator it;
318  for ( it = attlist.begin(); it != attlist.end(); ++it) {
319  NextElement();
320  WriteKey(it->GetName());
321  WriteValue(it->GetValue(),eStringTypeUTF8);
322  }
323  m_SkippedMemberId = obj_name;
325  EndBlock();
326 }
327 
329 {
330  CAnyContentObject obj;
331  in.ReadAnyContentObject(obj);
333 }
334 
335 
337 {
338  m_Output.PutChar('\"');
339 #if BITSTRING_AS_VECTOR
340  static const char ToHex[] = "0123456789ABCDEF";
341  Uint1 data, mask;
342  bool done = false;
343  for ( CBitString::const_iterator i = obj.begin(); !done; ) {
344  for (data=0, mask=0x8; !done && mask!=0; mask = Uint1(mask >> 1)) {
345  if (*i) {
346  data |= mask;
347  }
348  done = (++i == obj.end());
349  }
350  m_Output.PutChar(ToHex[data]);
351  }
352 #else
353  if (IsCompressed()) {
355  CBitString::statistics st;
356  obj.calc_stat(&st);
357  char* buf = (char*)malloc(st.max_serialize_mem);
358  size_t len = bm::serialize(obj, (unsigned char*)buf, tmp_block);
359  WriteBytes(buf,len);
360  free(buf);
361  bm::aligned_free(tmp_block);
362  } else {
364  CBitString::size_type ilast = obj.size();
365  CBitString::enumerator e = obj.first();
366  for (; i < ilast; ++i) {
367  m_Output.PutChar( (i == *e) ? '1' : '0');
368  if (i == *e) {
369  ++e;
370  }
371  }
372  }
373 #endif
374  m_Output.PutString("B\"");
375 }
376 
378 {
379  ThrowError(fNotImplemented, "Not Implemented");
380 }
381 
384 {
385  string value_str;
386  if (values.IsInteger()) {
387  value_str = NStr::IntToString(value);
388  const string& name = values.FindNameEx(value, values.IsInteger());
389  if (name.empty() || GetWriteNamedIntegersByValue()) {
390  WriteKeywordValue(value_str);
391  } else {
392  WriteValue(name);
393  }
394  } else {
395  value_str = values.FindNameEx(value, values.IsInteger());
396  WriteValue(value_str);
397  }
398 }
399 
402 {
403  TEnumValueType value = in.ReadEnum(values);
404  WriteEnum(values, value);
405 }
406 
408  TTypeInfo memberType,
409  TConstObjectPtr memberPtr)
410 {
411  CObjectOStream::WriteClassMember(memberId,memberType,memberPtr);
412 }
413 
415  const CDelayBuffer& buffer)
416 {
417  return CObjectOStream::WriteClassMember(memberId,buffer);
418 }
419 
421  const CMemberId& memberId, TTypeInfo memberType,
422  TConstObjectPtr memberPtr, ESpecialCaseWrite how)
423 {
424  if (how == eWriteAsNil) {
425  BeginClassMember(memberId);
426  WriteKeywordValue("null");
427  EndClassMember();
428  }
429 }
430 
432 {
433  CObjectOStream::BeginNamedType(namedTypeInfo);
434 }
435 
437 {
439 }
440 
441 
443 {
445  if (type.GetTypeFamily() == eTypeFamilyPrimitive && type.GetPrimitiveValueType() == ePrimitiveValueAny) {
446  TopFrame().SetNotag();
447  m_BlockStart = true;
448  m_ExpectValue = false;
449  return;
450  }
451  BeginArray();
452 }
453 
455 {
456  if (TopFrame().GetNotag()) {
457  TopFrame().SetNotag(false);
458  return;
459  }
460  EndArray();
461 }
462 
464 {
465  NextElement();
466 }
467 
469 {
470 }
471 
472 
474 {
475  if (GetStackDepth() > 1 && FetchFrameFromTop(1).GetNotag()) {
476  return;
477  }
478  StartBlock();
479 }
480 
481 
483 {
484  if (GetStackDepth() > 1 && FetchFrameFromTop(1).GetNotag()) {
485  return;
486  }
487  EndBlock();
488 }
489 
491 {
492  if (m_ExpectValue) {
493  return;
494  }
495  if (id.HasNotag() || id.IsAttlist()) {
496  TopFrame().SetNotag();
497  if (id.HasAnyContent()) {
498 #if 1
499  if ( m_BlockStart ) {
500  m_BlockStart = false;
501  } else {
502  m_Output.PutChar(',');
503  }
504 #else
505  NextElement();
506 #endif
507  } else {
508  auto tn = [this]()->const string& {
509  const string& r(m_TypeAlias->GetName());
510  m_TypeAlias = nullptr;
511  return r;
512  };
513  m_SkippedMemberId = (m_TypeAlias && id.HasNotag()) ? tn() : id.GetName();
514  }
515  return;
516  }
517  if (id.HasAnyContent()) {
518  return;
519  }
520  NextElement();
521  WriteMemberId(id);
522 }
523 
525 {
526  if (TopFrame().GetNotag()) {
527  TopFrame().SetNotag(false);
528  }
529  m_ExpectValue = false;
530 }
531 
532 
534 {
535  if (GetStackDepth() > 1 && FetchFrameFromTop(1).GetNotag()) {
536  return;
537  }
538  StartBlock();
539 }
540 
542 {
543  if (GetStackDepth() > 1 && FetchFrameFromTop(1).GetNotag()) {
544  return;
545  }
546  EndBlock();
547 }
548 
550  const CMemberId& id)
551 {
552  if (id.HasNotag() || id.IsAttlist()) {
553  m_SkippedMemberId = id.GetName();
554  TopFrame().SetNotag();
555  return;
556  }
557  NextElement();
558  WriteMemberId(id);
559 }
560 
562 {
563  if (TopFrame().GetNotag()) {
564  TopFrame().SetNotag(false);
565  }
566  m_ExpectValue = false;
567 }
568 
569 
570 static const char* const HEX = "0123456789ABCDEF";
571 
573 {
574  if (m_BinaryFormat == eArray_Bool ||
577  m_Output.PutChar('[');
578  m_WrapAt = 78;
579  } else {
580  m_Output.PutChar('\"');
581  m_WrapAt = 0;
582  }
583 }
584 
586  const char* bytes, size_t length)
587 {
589  WriteCustomBytes(bytes,length);
590  return;
591  }
592  if (IsCompressed()) {
593  WriteBase64Bytes(bytes,length);
594  return;
595  }
596  WriteBytes(bytes,length);
597 }
598 
600 {
601  if (m_BinaryFormat == eArray_Bool ||
604  m_Output.BackChar(',');
605  m_Output.PutEol();
606  m_Output.PutChar(']');
607  } else {
608  if (m_BinaryFormat == eString_01B) {
609  m_Output.PutChar('B');
610  }
611  m_Output.PutChar('\"');
612  }
613 }
614 
615 void CObjectOStreamJson::WriteBase64Bytes(const char* bytes, size_t length)
616 {
617  const size_t chunk_in = 57;
618  const size_t chunk_out = 80;
619  if (length > chunk_in && m_WrapAt != 0) {
620  m_Output.PutEol(false);
621  }
622  char dst_buf[chunk_out];
623  size_t bytes_left = length;
624  size_t src_read=0, dst_written=0, line_len=0;
625  while (bytes_left > 0 && bytes_left <= length) {
626  BASE64_Encode(bytes, min(bytes_left,chunk_in), &src_read,
627  dst_buf, chunk_out, &dst_written, &line_len);
628  m_Output.PutString(dst_buf,dst_written);
629  bytes_left -= src_read;
630  bytes += src_read;
631  if (bytes_left > 0 && m_WrapAt != 0) {
632  m_Output.PutEol(false);
633  }
634  }
635  if (length > chunk_in && m_WrapAt != 0) {
636  m_Output.PutEol(false);
637  }
638 }
639 
640 void CObjectOStreamJson::WriteBytes(const char* bytes, size_t length)
641 {
642  while ( length-- > 0 ) {
643  char c = *bytes++;
644  m_Output.PutChar(HEX[(c >> 4) & 0xf]);
645  m_Output.PutChar(HEX[c & 0xf]);
646  }
647 }
648 
649 void CObjectOStreamJson::WriteCustomBytes(const char* bytes, size_t length)
650 {
652  WriteBase64Bytes(bytes, length);
653  return;
654  } else if (m_BinaryFormat == eString_Hex) {
655  WriteBytes(bytes, length);
656  return;
657  }
658  if (m_WrapAt != 0 &&
662  m_Output.PutEol(false);
663  }
664  while ( length-- > 0 ) {
665  Uint1 c = *bytes++;
666  Uint1 mask=0x80;
667  switch (m_BinaryFormat) {
668  case eArray_Bool:
669  for (; mask!=0; mask = Uint1(mask >> 1)) {
670  if (m_WrapAt != 0) {
671  m_Output.WrapAt(m_WrapAt, false);
672  }
673  m_Output.PutString( (mask & c) ? "true" : "false");
674  m_Output.PutChar(',');
675  }
676  break;
677  case eArray_01:
678  for (; mask!=0; mask = Uint1(mask >> 1)) {
679  if (m_WrapAt != 0) {
680  m_Output.WrapAt(m_WrapAt, false);
681  }
682  m_Output.PutChar( (mask & c) ? '1' : '0');
683  m_Output.PutChar(',');
684  }
685  break;
686  default:
687  case eArray_Uint:
688  if (m_WrapAt != 0) {
689  m_Output.WrapAt(m_WrapAt, false);
690  }
691  m_Output.PutString( NStr::UIntToString((unsigned int)c));
692  m_Output.PutChar(',');
693  break;
694  case eString_01:
695  case eString_01B:
696  for (; mask!=0; mask = Uint1(mask >> 1)) {
697  m_Output.PutChar( (mask & c) ? '1' : '0');
698  }
699  break;
700  }
701  }
702 }
703 
705  const char* /*chars*/, size_t /*length*/)
706 {
707  ThrowError(fNotImplemented, "Not Implemented");
708 }
709 
710 
712 {
713 }
714 
716 {
717  WriteKey(id.GetName());
718  m_SkippedMemberId.erase();
719 }
720 
722 {
723  string name("#");
724  name += m_SkippedMemberId;
725  NextElement();
726  WriteKey(name);
727  m_SkippedMemberId.erase();
728 }
729 
730 
732 {
733  switch ( c ) {
734  case '"':
735  m_Output.PutString("\\\"");
736  break;
737  case '\\':
738  m_Output.PutString("\\\\");
739  break;
740  default:
741  if ( (unsigned int)c < 0x20 ||
742  ((unsigned int)c >= 0x80 && enc_in != eEncoding_UTF8) ) {
743  m_Output.PutString("\\u00");
744  Uint1 ch = c;
745  unsigned hi = ch >> 4;
746  unsigned lo = ch & 0xF;
747  m_Output.PutChar(HEX[hi]);
748  m_Output.PutChar(HEX[lo]);
749  } else {
750  m_Output.PutChar(c);
751  }
752  break;
753  }
754 }
755 
757 {
759  EEncoding enc_out(eEncoding_UTF8);
760 
761  if (enc_in == enc_out || enc_in == eEncoding_Unknown || (*src & 0x80) == 0) {
762  WriteEscapedChar(*src, enc_in);
763  } else {
764  CStringUTF8 tmp( CUtf8::AsUTF8( CTempString(src,1),enc_in));
765  for ( string::const_iterator t = tmp.begin(); t != tmp.end(); ++t ) {
766  m_Output.PutChar(*t);
767  }
768  }
769 }
770 
772 {
773  m_Output.PutChar('\"');
774  for (const char* src = value.c_str(); *src; ++src) {
775  WriteEncodedChar(src,type);
776  }
777  m_Output.PutChar('\"');
778 }
779 
781 {
782  string s(key);
783  if (!m_PreserveKeys) {
784  NStr::ReplaceInPlace(s,"-","_");
785  }
786  x_WriteString(s);
787  NameSeparator();
788 }
789 
791 {
792  if (!m_ExpectValue && !m_SkippedMemberId.empty()) {
794  }
795 }
796 
798 {
799  BeginValue();
801  m_ExpectValue = false;
802 }
803 
805 {
806  BeginValue();
808  m_ExpectValue = false;
809 }
810 
812 {
813  BeginValue();
814  m_Output.PutChar('{');
816  m_BlockStart = true;
817  m_ExpectValue = false;
818 }
819 
821 {
823  m_Output.PutEol();
824  m_Output.PutChar('}');
825  m_BlockStart = false;
826  m_ExpectValue = false;
827 }
828 
830 {
831  if ( m_BlockStart ) {
832  m_BlockStart = false;
833  } else {
834  m_Output.PutChar(',');
835  }
836  m_Output.PutEol();
837  m_ExpectValue = true;
838 }
839 
841 {
842  BeginValue();
843  m_Output.PutChar('[');
845  m_BlockStart = true;
846  m_ExpectValue = false;
847 }
848 
850 {
852  m_Output.PutEol();
853  m_Output.PutChar(']');
854  m_BlockStart = false;
855  m_ExpectValue = false;
856 }
857 
859 {
860  m_Output.PutChar(':');
861  if (m_Output.GetUseIndentation()) {
862  m_Output.PutChar(' ');
863  }
864  m_ExpectValue = true;
865 }
866 
ncbi::TMaskedQueryRegions mask
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:264
CDelayBuffer.
Definition: delaybuf.hpp:58
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStreamJson –.
Definition: objostrjson.hpp:54
CObjectOStream –.
Definition: objostr.hpp:83
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
size_type size() const noexcept
Returns bvector's capacity (number of bits it can store)
Definition: bm.h:1300
friend class enumerator
Definition: bm.h:793
bvector_size_type size_type
Definition: bm.h:121
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
Definition: bm.h:1871
enumerator end() const
Returns enumerator pointing on the next bit after the last.
Definition: bm.h:1877
void calc_stat(struct bm::bvector< Alloc >::statistics *st) const noexcept
Calculates bitvector statistics.
Definition: bm.h:3978
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
#define false
Definition: bool.h:36
static int type
Definition: getdata.c:31
static const char * str(char *buf, int n)
Definition: stats.c:84
static char tmp[3200]
Definition: utf8.c:42
char data[12]
Definition: iconv.c:80
@ eDefault
Definition: ncbi_types.h:112
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
@ eNoOwnership
No ownership is assumed.
Definition: ncbi_types.h:135
#define isnan
Definition: ncbifloat.h:89
#define finite
Define value of finite (Is Finite).
Definition: ncbifloat.h:109
const string & GetName(void) const
const string & FindNameEx(TEnumValueType value, bool allowBadValue) const
Definition: enumerated.cpp:163
bool IsInteger(void) const
Check whether the type is defined as INTEGER in ASN.1 spec.
Definition: enumvalues.hpp:75
const CStringUTF8 & GetValue(void) const
Get normalized value.
int TEnumValueType
Definition: serialdef.hpp:232
const void * TConstObjectPtr
Definition: serialdef.hpp:59
EStringType
String type.
Definition: serialdef.hpp:185
const string & GetName(void) const
Get local name.
const vector< CSerialAttribInfoItem > & GetAttributes(void) const
Get object attributes.
@ ePrimitiveValueAny
Definition: serialdef.hpp:160
@ eTypeFamilyPrimitive
Definition: serialdef.hpp:139
@ eStringTypeUTF8
UTF8-encoded string.
Definition: serialdef.hpp:187
@ eSerial_Json
JSON.
Definition: serialdef.hpp:76
virtual void WriteString(const string &s, EStringType type=eStringTypeVisible) override
virtual void CopyStringStore(CObjectIStream &in) override
virtual void WriteFileHeader(TTypeInfo type) override
EBinaryDataFormat
formatting of binary data ('OCTET STRING', 'hexBinary', 'base64Binary')
Definition: objostrjson.hpp:93
void GetJsonpPadding(string *prefix, string *suffix) const
Get JSONP padding (prefix and suffix)
void BeginValue(void)
virtual void BeginContainerElement(TTypeInfo elementType) override
bool m_FastWriteDouble
Definition: objostr.hpp:806
MLIOVIR void WriteClassMemberSpecialCase(const CMemberId &memberId, TTypeInfo memberType, TConstObjectPtr memberPtr, ESpecialCaseWrite how)
Definition: objostr.cpp:580
void WriteClassMember(const CConstObjectInfoMI &member)
Definition: objostr.cpp:571
void WriteDouble2(double data, unsigned digits)
virtual void WriteSeparator(void) override
virtual void EndContainer(void) override
EBinaryDataFormat GetBinaryDataFormat(void) const
Get formatting of binary data.
virtual void CopyAnyContentObject(CObjectIStream &in) override
virtual void WriteOtherEnd(TTypeInfo typeInfo) override
static TTypeInfo GetRealTypeInfo(TTypeInfo typeInfo)
Definition: objstack.cpp:331
virtual string GetPosition(void) const override
Get current stream position as string.
virtual void WriteAnyContentObject(const CAnyContentObject &obj) override
void WriteEscapedChar(char c, EEncoding enc_in)
virtual void EndBytes(const ByteBlock &block) override
#define ThrowError(flag, mess)
Definition: objstack.hpp:113
void SetJsonpMode(const string &function_name)
Set JSONP mode JSONP prefix will become "function_name(" JSONP suffix will become ");".
void WriteCustomBytes(const char *bytes, size_t length)
virtual void EndClass(void) override
virtual void EndChoice(void) override
bool IsCompressed(void) const
Definition: objstack.cpp:193
virtual ~CObjectOStreamJson(void)
Destructor.
Definition: objostrjson.cpp:96
virtual void WriteInt4(Int4 data) override
virtual void WriteNull(void) override
virtual void WriteUint8(Uint8 data) override
void x_WriteString(const string &value, EStringType type=eStringTypeVisible)
void NameSeparator(void)
void BeginArray(void)
void WriteKeywordValue(const string &value)
EEncoding m_StringEncoding
virtual void BeginNamedType(TTypeInfo namedTypeInfo)
Definition: objostr.cpp:734
virtual void EndNamedType(void) override
void SetNotag(bool set=true)
void WriteEncodedChar(const char *&src, EStringType type)
void WriteMemberId(const CMemberId &id)
TFrame & FetchFrameFromTop(size_t index)
virtual void EndOfWrite(void) override
virtual void BeginChoiceVariant(const CChoiceTypeInfo *choiceType, const CMemberId &id) override
virtual void BeginContainer(const CContainerTypeInfo *containerType) override
virtual void WriteOther(TConstObjectPtr object, TTypeInfo typeInfo) override
void WriteKey(const string &key)
size_t GetStackDepth(void) const
size_t TObjectIndex
Definition: objostr.hpp:775
virtual void BeginChoice(const CChoiceTypeInfo *choiceType) override
virtual void WriteFloat(float data) override
void WriteValue(const string &value, EStringType type=eStringTypeVisible)
const TFrame & TopFrame(void) const
static CObjectOStream * OpenObjectOStreamJson(CNcbiOstream &out, EOwnership deleteOut)
Definition: objostrjson.cpp:60
virtual void WriteStringStore(const string &s) override
virtual void WriteBool(bool data) override
virtual void EndOfWrite(void)
Definition: objostr.cpp:559
virtual void WriteChar(char data) override
virtual void WriteEnum(const CEnumeratedTypeValues &values, TEnumValueType value) override
virtual void CopyBitString(CObjectIStream &in) override
EBinaryDataFormat m_BinaryFormat
CObjectOStreamJson(CNcbiOstream &out, bool deleteOut)
Constructor.
Definition: objostrjson.cpp:68
bool GetWriteNamedIntegersByValue(void) const
Get writing named integers by value parameter.
COStreamBuffer m_Output
Definition: objostr.hpp:796
bool StackIsEmpty(void) const
const CMemberId & GetMemberId(void) const
virtual void EndContainerElement(void) override
virtual void BeginClassMember(const CMemberId &id) override
virtual void WriteBytes(const ByteBlock &block, const char *bytes, size_t length) override
TTypeInfo m_TypeAlias
Definition: objostr.hpp:808
virtual void BeginNamedType(TTypeInfo namedTypeInfo) override
virtual void EndClassMember(void) override
virtual void WriteCString(const char *str) override
EEncoding GetDefaultStringEncoding(void) const
Get default encoding of 'string' objects.
virtual void WriteChars(const CharBlock &block, const char *chars, size_t length) override
virtual void WriteBitString(const CBitString &obj) override
EFrameType GetFrameType(void) const
void SetBinaryDataFormat(EBinaryDataFormat fmt)
Set formatting of binary data.
bool m_WriteNamedIntegersByValue
Definition: objostr.hpp:805
void WriteSkippedMember(void)
virtual void CopyString(CObjectIStream &in, EStringType type=eStringTypeVisible) override
void NextElement(void)
virtual void EndChoiceVariant(void) override
virtual void CopyEnum(const CEnumeratedTypeValues &values, CObjectIStream &in) override
virtual void WriteInt8(Int8 data) override
virtual void WriteNullPointer(void) override
virtual void WriteUint4(Uint4 data) override
virtual void EndNamedType(void)
Definition: objostr.cpp:738
void StartBlock(void)
virtual void BeginBytes(const ByteBlock &block) override
virtual void WriteObjectReference(TObjectIndex index) override
virtual void WriteDouble(double data) override
virtual void WriteOtherBegin(TTypeInfo typeInfo) override
void WriteBase64Bytes(const char *bytes, size_t length)
bool m_EnforceWritingDefaults
Definition: objostr.hpp:807
void SetDefaultStringEncoding(EEncoding enc)
Set default encoding of 'string' objects.
virtual void BeginClass(const CClassTypeInfo *classInfo) override
@ eString_01B
string of 0 and 1, plus 'B' at the end
@ eArray_Uint
array of unsigned integers
Definition: objostrjson.hpp:97
@ eArray_Bool
array of 'true' and 'false'
Definition: objostrjson.hpp:95
@ eArray_01
array of 1 and 0
Definition: objostrjson.hpp:96
@ eString_Hex
HEX string.
Definition: objostrjson.hpp:98
@ eString_Base64
Base64Binary string.
@ eString_01
string of 0 and 1
Definition: objostrjson.hpp:99
@ fInvalidData
Output data is incorrect.
Definition: objostr.hpp:322
@ fNotImplemented
Method is not implemented.
Definition: objostr.hpp:330
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::string CStringUTF8
Definition: ncbistl.hpp:254
void IncIndentLevel(size_t step=2)
bool GetUseIndentation(void) const
void PutChar(char c)
void BackChar(char c)
size_t GetLine(void) const
void PutString(const char *str, size_t length)
void PutEol(bool indent=true)
void WrapAt(size_t lineLength, bool keepWord)
void DecIndentLevel(size_t step=2)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
EEncoding
Definition: ncbistr.hpp:199
static string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)
Convert size_t to string.
Definition: ncbistr.cpp:2751
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
Definition: ncbistr.hpp:5159
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
Definition: ncbistr.hpp:5187
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static SIZE_TYPE DoubleToStringPosix(double value, unsigned int precision, char *buf, SIZE_TYPE buf_size)
Convert double to string with specified precision and put the result into a character buffer,...
Definition: ncbistr.cpp:2662
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3889
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
Definition: ncbistr.hpp:5109
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
static string UInt8ToString(Uint8 value, TNumToStringFlags flags=0, int base=10)
Convert UInt8 to string.
Definition: ncbistr.hpp:5168
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
@ eEncoding_Unknown
Definition: ncbistr.hpp:200
@ fDoublePosix
DoubleToString*(): Use C locale for double conversions.
Definition: ncbistr.hpp:257
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
TTypeInfo GetElementType(void) const
enum ENcbiOwnership EOwnership
Ownership relations between objects.
size_t serialize(const BV &bv, unsigned char *buf, bm::word_t *temp_block=0, unsigned serialization_flags=0)
Saves bitvector into memory.
Definition: bmserial.h:3071
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
char * buf
int i
int len
unsigned int word_t
Definition: bmconst.h:39
void aligned_free(void *ptr) BMNOEXCEPT
Aligned free.
Definition: bmalloc.h:464
void * aligned_new_malloc(size_t size)
Aligned malloc (unlike classic malloc it throws bad_alloc exception)
Definition: bmalloc.h:436
const unsigned set_block_alloc_size
Definition: bmconst.h:61
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
EIPRangeType t
Definition: ncbi_localip.c:101
T min(T x_, T y_)
std::istream & in(std::istream &in_, double &x_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static const char *const HEX
static const char * suffix[]
Definition: pcregrep.c:408
static const char * prefix[]
Definition: pcregrep.c:405
static pcre_uint8 * buffer
Definition: pcretest.c:1051
#define BASE64_Encode
Definition: ncbi_base64.h:41
Definition: type.c:6
done
Definition: token1.c:1
void free(voidpf ptr)
voidp malloc(uInt size)
Modified on Wed May 01 14:20:58 2024 by modify_doxy.py rev. 669887