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

Go to the SVN repository for this file.

1 /* $Id: statictype.cpp 92634 2021-02-02 14:31:09Z ivanov $
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 * Type descriptions of predefined types
30 */
31 
32 #include <ncbi_pch.hpp>
33 #include "exceptions.hpp"
34 #include "statictype.hpp"
35 #include "stdstr.hpp"
36 #include "stlstr.hpp"
37 #include "value.hpp"
38 #include "blocktype.hpp"
39 #include "srcutil.hpp"
40 #include <serial/impl/stdtypes.hpp>
41 #include <serial/impl/stltypes.hpp>
43 #include <typeinfo>
44 #include <vector>
45 #include <common/ncbi_sanitizers.h>
46 
47 
49 
50 
52 {
53  NCBI_THROW(CDatatoolException, eNotImplemented,
54  GetASNKeyword() + string(" default not implemented"));
55 }
56 
57 void CStaticDataType::PrintASN(CNcbiOstream& out, int /*indent*/) const
58 {
60  out << GetASNKeyword();
61 }
62 
63 void CStaticDataType::PrintJSONSchema(CNcbiOstream& out, int indent, list<string>& required, bool) const
64 {
65  string asnk(GetASNKeyword());
66  const CDataMember* mem = GetDataMember();
67  string type("string");
68  if (asnk == "NULL") {
69  type = "null";
70  } else if (asnk == "BOOLEAN") {
71  type = "boolean";
72  } else if (asnk == "INTEGER" || asnk == "BigInt") {
73  type = "integer";
74  } else if (asnk == "REAL") {
75  type = "number";
76  }
78  if (IsNillable()) {
79  out << "\"oneOf\": [{";
80  }
81  out << "\"type\": \"" << type << "\"";
82  if (mem) {
83  const list<CMemberFacet>& con = mem->GetRestrictions();
84  string pattern;
85  for (const CMemberFacet& f : con) {
86  string fname;
87  switch (f.GetType()) {
89  out << ","; PrintASNNewLine(out, indent) << "\"minLength\": " << f.GetValue();
90  break;
92  out << ","; PrintASNNewLine(out, indent) << "\"maxLength\": " << f.GetValue();
93  break;
95  out << ","; PrintASNNewLine(out, indent) << "\"exclusiveMinimum\": " << f.GetValue();
96  break;
98  out << ","; PrintASNNewLine(out, indent) << "\"minimum\": " << f.GetValue();
99  break;
101  out << ","; PrintASNNewLine(out, indent) << "\"exclusiveMaximum\": " << f.GetValue();
102  break;
104  out << ","; PrintASNNewLine(out, indent) << "\"maximum\": " << f.GetValue();
105  break;
107  out << ","; PrintASNNewLine(out, indent) << "\"multipleOf\": " << f.GetValue();
108  break;
110  if (!pattern.empty()) {
111  pattern.append("|");
112  }
113  pattern.append(f.GetValue());
114  break;
115  default: break;
116  }
117  }
118  if (!pattern.empty()) {
119  out << ","; PrintASNNewLine(out, indent) << "\"pattern\": \"" << pattern << "\"";
120  }
121  }
122  if (IsNillable()) {
123  out << "}, {\"type\": \"null\"}]";
124  }
125  if (mem) {
126  if (mem->GetDefault()) {
127  out << ", \"default\": \"" << mem->GetDefault()->GetXmlString() << "\"";
128  }
129  if (!mem->Optional()) {
130  if (mem->SimpleType()) {
131  required.push_back(string("#") + mem->GetName());
132  } else {
133  required.push_back(mem->GetName());
134  }
135  }
136  }
137 }
138 
139 // XML schema generator submitted by
140 // Marc Dumontier, Blueprint initiative, dumontier@mshri.on.ca
141 // modified by Andrei Gourianov, gouriano@ncbi
143  int indent, bool /*contents_only*/) const
144 {
145  string tag( XmlTagName());
146  string xsdk("element"), use, form;
147  const CDataMember* mem = GetDataMember();
148  bool optional = mem ? mem->Optional() : false;
149  bool isGlobalType = GetGlobalType() == CDataType::eType;
150  bool hasFacets = mem ? !mem->GetRestrictions().empty() : !GetRestrictions().empty();
151 
152  if (isGlobalType) {
153  xsdk = "complexType";
154  }
155  if (GetParentType() && GetParentType()->GetDataMember()) {
156  if (GetParentType()->GetDataMember()->Attlist()) {
157  xsdk = "attribute";
158  if (optional) {
159  use = "optional";
160  if (mem->GetDefault()) {
161  use += "\" default=\"" + mem->GetDefault()->GetXmlString();
162  }
163  } else {
164  use = "required";
165  }
166  if (IsNsQualified() == eNSQualified) {
167  form = " form=\"qualified\"";
168  }
169  }
170  }
171  PrintASNNewLine(out, indent) << "<xs:" << xsdk << " name=\"" << tag << "\"";
172  string type = GetSchemaTypeString();
173  if (!isGlobalType && !type.empty() && !hasFacets) {
174  out << " type=\"" << type << "\"";
175  }
176  if (!use.empty()) {
177  out << " use=\"" << use << "\"";
178  } else {
179  if (!IsASNDataSpec()) {
180  if (optional) {
181  out << " minOccurs=\"0\"";
182  }
183  if (mem && mem->GetDefault()) {
184  out << " default=\"" << mem->GetDefault()->GetXmlString() << "\"";
185  }
186  } else {
187  const CBoolDataType* bt = dynamic_cast<const CBoolDataType*>(this);
188  if (mem && optional) {
189  if (bt) {
190  out << " minOccurs=\"0\"";
191  } else {
192  if (mem->GetDefault()) {
193  out << " default=\"" << mem->GetDefault()->GetXmlString() << "\"";
194  } else {
195  out << " minOccurs=\"0\"";
196  }
197  }
198  }
199  }
200  }
201  if (!form.empty()) {
202  out << form;
203  }
204  if (IsNillable()) {
205  out << " nillable=\"true\"";
206  }
207  if (isGlobalType && !type.empty()) {
208  out << ">";
209  PrintASNNewLine(out, ++indent) << "<xs:simpleContent>";
210  PrintASNNewLine(out, ++indent) << "<xs:extension base=\"" << type << "\"/>";
211  PrintASNNewLine(out, --indent) << "</xs:simpleContent>";
212  PrintASNNewLine(out, --indent) << "</xs:" << xsdk << ">";
213  return;
214  }
215  if (hasFacets && !type.empty()) {
216  out << ">";
217  PrintASNNewLine(out, ++indent) << "<xs:simpleType>";
218  PrintASNNewLine(out, ++indent) << "<xs:restriction base=\"" << type << "\">";
219  ++indent;
220  const list<CMemberFacet>& con = mem ? mem->GetRestrictions() : GetRestrictions();
221  for (const CMemberFacet& f : con) {
222  string fname;
223  switch (f.GetType()) {
224  case ESerialFacet::eMinLength: fname = "minLength"; break;
225  case ESerialFacet::eMaxLength: fname = "maxLength"; break;
226  case ESerialFacet::eLength: fname = "length"; break;
227  case ESerialFacet::ePattern: fname = "pattern"; break;
228  case ESerialFacet::eInclusiveMinimum: fname = "minInclusive"; break;
229  case ESerialFacet::eExclusiveMinimum: fname = "minExclusive"; break;
230  case ESerialFacet::eInclusiveMaximum: fname = "maxInclusive"; break;
231  case ESerialFacet::eExclusiveMaximum: fname = "maxExclusive"; break;
232  default: break;
233  }
234  if (!fname.empty()) {
235  PrintASNNewLine(out, indent) << "<xs:" << fname << " value=\"" << f.GetValue() << "\"/>";
236  }
237  }
238  PrintASNNewLine(out, --indent) << "</xs:restriction>";
239  PrintASNNewLine(out, --indent) << "</xs:simpleType>";
240  PrintASNNewLine(out, --indent) << "</xs:" << xsdk << ">";
241  return;
242  }
243  if (PrintXMLSchemaContents(out,indent+1,mem)) {
244  PrintASNNewLine(out, indent) << "</xs:" << xsdk << ">";
245  } else {
246  out << "/>";
247  }
248 }
249 
251 {
252 #if _DATATOOL_USE_SCHEMA_STYLE_COMMENTS
253  const CComments& cm(mem ? mem->GetComments() : Comments());
254  return cm.PrintSchemaComments(out,indent);
255 #else
256  return false;
257 #endif
258 }
259 
260 void CStaticDataType::PrintDTDElement(CNcbiOstream& out, bool contents_only) const
261 {
262  string tag(XmlTagName());
263  string content(GetXMLContents());
264  if (GetParentType() &&
266  GetParentType()->GetDataMember()->Attlist()) {
267  const CDataMember* mem = GetDataMember();
268  out << "\n " << tag;
269  const CBoolDataType* bt = dynamic_cast<const CBoolDataType*>(this);
270  if (bt) {
271  out << " ( true | false ) ";
272  } else {
273  out << " CDATA ";
274  }
275  if (mem->GetDefault()) {
276  out << "\"" << mem->GetDefault()->GetXmlString() << "\"";
277  } else {
278  if (mem->Optional()) {
279  out << "#IMPLIED";
280  } else {
281  out << "#REQUIRED";
282  }
283  }
284  } else {
285  string open("("), close(")");
286  if (content == "EMPTY") {
287  open.erase();
288  close.erase();
289  }
290  if (!contents_only) {
291  out << "\n<!ELEMENT " << tag << ' ' << open;
292  }
293  out << content;
294  if (!contents_only) {
295  out << close << ">";
296  }
297  }
298 }
299 
301 {
302  string storage = GetVar("_storage_type");
303  string type = GetAndVerifyVar("_type");
304  bool full_ns = !type.empty();
305  if ( type.empty() )
306  type = GetDefaultCType();
308  if (!storage.empty()) {
309  a->SetStorageType(storage);
310  }
311  if (!type.empty()) {
312  if (NStr::EndsWith(type, "CStrictId")) {
313  (dynamic_cast<CStdTypeStrings*>(a.get()))->SetBigInt();
314  }
315  }
316  return a;
317 }
318 
319 const char* CNullDataType::GetASNKeyword(void) const
320 {
321  return "NULL";
322 }
323 
324 const char* CNullDataType::GetDEFKeyword(void) const
325 {
326  return "_NULL_";
327 }
328 
329 const char* CNullDataType::GetXMLContents(void) const
330 {
331  return "EMPTY";
332 }
333 
335 {
336 #if _DATATOOL_USE_SCHEMA_STYLE_COMMENTS
339  return false;
340  }
341  out << ">";
342  }
343 #else
344  if (IsGlobalType()) {
345  return false;
346  }
347  out << ">";
348 #endif
349  PrintASNNewLine(out, indent) << "<xs:complexType/>";
350  return true;
351 }
352 
354 {
356  return true;
357 }
358 
360 {
361  NCBI_THROW(CDatatoolException, eNotImplemented,
362  "NULL cannot have DEFAULT");
363 }
364 
366 {
367  if ( HaveModuleName() )
370 }
371 
373 {
375 }
376 
377 const char* CNullDataType::GetDefaultCType(void) const
378 {
379  return "bool";
380 }
381 
382 const char* CBoolDataType::GetASNKeyword(void) const
383 {
384  return "BOOLEAN";
385 }
386 
387 const char* CBoolDataType::GetDEFKeyword(void) const
388 {
389  return "_BOOLEAN_";
390 }
391 
392 const char* CBoolDataType::GetXMLContents(void) const
393 {
394 // return "%BOOLEAN;";
395  return "EMPTY";
396 }
397 
399 {
400  if (!IsASNDataSpec()) {
401  return "xs:boolean";
402  }
403  if (GetParentType() &&
405  GetParentType()->GetDataMember()->Attlist()) {
406  return "xs:boolean";
407  }
408  return kEmptyStr;
409 }
410 
412 {
413 #if _DATATOOL_USE_SCHEMA_STYLE_COMMENTS
414  bool tagclosed = CStaticDataType::PrintXMLSchemaContents(out, indent, mem);
415 #else
416  bool tagclosed = false;
417 #endif
418  if (!IsASNDataSpec()) {
419  return tagclosed;
420  }
421  if (GetParentType() &&
423  GetParentType()->GetDataMember()->Attlist()) {
424  return tagclosed;
425  }
426  if (!tagclosed) {
427  out << ">";
428  }
429  const CBoolDataValue *val = GetDataMember() ?
430  dynamic_cast<const CBoolDataValue*>(GetDataMember()->GetDefault()) : 0;
431 
432  PrintASNNewLine(out,indent++) << "<xs:complexType>";
433  PrintASNNewLine(out,indent++) << "<xs:attribute name=\"value\" use=";
434  if (val) {
435  out << "\"optional\" default=";
436  if (val->GetValue()) {
437  out << "\"true\"";
438  } else {
439  out << "\"false\"";
440  }
441  } else {
442  out << "\"required\"";
443  }
444  out << ">";
445  PrintASNNewLine(out,indent++) << "<xs:simpleType>";
446  PrintASNNewLine(out,indent++) << "<xs:restriction base=\"xs:string\">";
447  PrintASNNewLine(out,indent) << "<xs:enumeration value=\"true\"/>";
448  PrintASNNewLine(out,indent) << "<xs:enumeration value=\"false\"/>";
449  PrintASNNewLine(out,--indent) << "</xs:restriction>";
450  PrintASNNewLine(out,--indent) << "</xs:simpleType>";
451  PrintASNNewLine(out,--indent) << "</xs:attribute>";
452  PrintASNNewLine(out,--indent) << "</xs:complexType>";
453  return true;
454 }
455 
457 {
458  const char *attr;
459  const CBoolDataValue *val = GetDataMember() ?
460  dynamic_cast<const CBoolDataValue*>(GetDataMember()->GetDefault()) : 0;
461 
462  if(val) {
463  attr = val->GetValue() ? "\"true\"" : "\"false\"";
464  }
465  else {
466  attr = "#REQUIRED";
467  }
468 
469  out <<
470  "\n<!ATTLIST "<<XmlTagName()<<" value ( true | false ) "
471  << attr << " >\n";
472 }
473 
475 {
476  CheckValueType(value, CBoolDataValue, "BOOLEAN");
477  return true;
478 }
479 
481 {
482  return new bool(dynamic_cast<const CBoolDataValue&>(value).GetValue());
483 }
484 
486 {
487  return (dynamic_cast<const CBoolDataValue&>(value).GetValue()?
488  "true": "false");
489 }
490 
492 {
493  if ( HaveModuleName() )
496 }
497 
498 const char* CBoolDataType::GetDefaultCType(void) const
499 {
500  return "bool";
501 }
502 
504 {
505  ForbidVar("_type", "string");
506 }
507 
508 const char* CRealDataType::GetASNKeyword(void) const
509 {
510  return "REAL";
511 }
512 
513 const char* CRealDataType::GetDEFKeyword(void) const
514 {
515  return "_REAL_";
516 }
517 
518 const char* CRealDataType::GetXMLContents(void) const
519 {
520  return DTDEntitiesEnabled() ? "%REAL;" : "#PCDATA";
521 }
522 
524 {
525  return "xs:double";
526 }
527 
529 {
530  const CBlockDataValue* block = dynamic_cast<const CBlockDataValue*>(&value);
531  if ( !block ) {
532  return dynamic_cast<const CDoubleDataValue*>(&value) != 0 ||
533  dynamic_cast<const CIntDataValue*>(&value) != 0;
534  }
535  if ( block->GetValues().size() != 3 ) {
536  value.Warning("wrong number of elements in REAL value", 16);
537  return false;
538  }
539  for ( CBlockDataValue::TValues::const_iterator i = block->GetValues().begin();
540  i != block->GetValues().end(); ++i ) {
541  CheckValueType(**i, CIntDataValue, "INTEGER");
542  }
543  return true;
544 }
545 
547 {
548  double d=0.;
549  const CDoubleDataValue* dbl = dynamic_cast<const CDoubleDataValue*>(&value);
550  if (dbl) {
551  d = dbl->GetValue();
552  } else {
553  const CIntDataValue* i = dynamic_cast<const CIntDataValue*>(&value);
554  if (i) {
555  d = (double)(i->GetValue());
556  }
557  }
558  return new double(d);
559 }
560 
562 {
563  const CDoubleDataValue* dbl = dynamic_cast<const CDoubleDataValue*>(&value);
564  if (dbl) {
565  return NStr::DoubleToString(dbl->GetValue(),
567  } else {
568  const CIntDataValue* i = dynamic_cast<const CIntDataValue*>(&value);
569  if (i) {
570  return NStr::DoubleToString((double)(i->GetValue()),
572  }
573  }
574  value.Warning("REAL value expected", 17);
575  return kEmptyStr;
576 }
577 
579 {
580  if ( HaveModuleName() )
583 }
584 
585 const char* CRealDataType::GetDefaultCType(void) const
586 {
587  return "double";
588 }
589 
591  : m_Type(type)
592 {
593  ForbidVar("_type", "short");
594  ForbidVar("_type", "int");
595  ForbidVar("_type", "long");
596  ForbidVar("_type", "unsigned");
597  ForbidVar("_type", "unsigned short");
598  ForbidVar("_type", "unsigned int");
599  ForbidVar("_type", "unsigned long");
600 }
601 
602 const char* CStringDataType::GetASNKeyword(void) const
603 {
604  if (m_Type == eStringTypeUTF8) {
605  return "UTF8String";
606  }
607  return "VisibleString";
608 }
609 
610 const char* CStringDataType::GetDEFKeyword(void) const
611 {
612  if (m_Type == eStringTypeUTF8) {
613  return "_UTF8String_";
614  }
615  return "_VisibleString_";
616 }
617 
618 const char* CStringDataType::GetXMLContents(void) const
619 {
620  return "#PCDATA";
621 }
622 
624 {
625  return "xs:string";
626 }
627 
629 {
631  return true;
632 }
633 
635 {
636 #if 0
637  if (m_Type == eStringTypeUTF8) {
638  return new (CStringUTF8*)(new CStringUTF8( CUtf8::AsUTF8(
639  dynamic_cast<const CStringDataValue&>(value).GetValue(), eEncoding_UTF8)));
640  }
641  return new (string*)(new string(dynamic_cast<const CStringDataValue&>(value).GetValue()));
642 #else
643  if (m_Type == eStringTypeUTF8) {
644  return (new CStringUTF8( CUtf8::AsUTF8(
645  dynamic_cast<const CStringDataValue&>(value).GetValue(), eEncoding_UTF8)));
646  }
647  return (new string(dynamic_cast<const CStringDataValue&>(value).GetValue()));
648 #endif
649 }
650 
652 {
653  string s;
654  s += '\"';
655  const string& v = dynamic_cast<const CStringDataValue&>(value).GetValue();
656  for ( string::const_iterator i = v.begin(); i != v.end(); ++i ) {
657  switch ( *i ) {
658  case '\r':
659  s += "\\r";
660  break;
661  case '\n':
662  s += "\\n";
663  break;
664  case '\"':
665  s += "\\\"";
666  break;
667  case '\\':
668  s += "\\\\";
669  break;
670  default:
671  s += *i;
672  }
673  }
674  return s + '\"';
675 }
676 
678 {
679  if ( HaveModuleName() )
681  if ( m_Type == eStringTypeUTF8 )
684 }
685 
687 {
688  return true;
689 }
690 
692 {
693  string type = GetAndVerifyVar("_type");
694  bool full_ns = !type.empty();
695  if ( type.empty() )
696  type = GetDefaultCType();
698  if (m_Type == eStringTypeUTF8) {
699  a->SetSpecialRef("CStringUTF8, ()");
700  }
701  return a;
702 }
703 
704 const char* CStringDataType::GetDefaultCType(void) const
705 {
706  if (m_Type == eStringTypeUTF8) {
707  return "NCBI_NS_NCBI::CStringUTF8";
708  }
709  return "NCBI_NS_STD::string";
710 }
711 
713 {
714 }
715 
716 const char* CStringStoreDataType::GetASNKeyword(void) const
717 {
718  return "StringStore";
719 }
720 
721 const char* CStringStoreDataType::GetDEFKeyword(void) const
722 {
723  return "_StringStore_";
724 }
725 
727 {
729 }
730 
732 {
733  return true;
734 }
735 
737 {
738  string type = GetAndVerifyVar("_type");
739  bool full_ns = !type.empty();
740  if ( type.empty() )
741  type = GetDefaultCType();
743 }
744 
745 const char* CBitStringDataType::GetASNKeyword(void) const
746 {
747  return "BIT STRING";
748 }
749 
750 const char* CBitStringDataType::GetDEFKeyword(void) const
751 {
752  return "_BIT_STRING_";
753 }
754 
756  : m_BitStringEnum(bitenum)
757 {
758 }
759 
761 {
762  if (m_BitStringEnum) {
764  }
765 }
766 
768 {
769  CheckValueType(value, CBitStringDataValue, "BIT STRING");
770  return true;
771 }
772 
774 {
775  if ( HaveModuleName() )
778 }
779 
781 {
782  return true;
783 }
784 
786 {
789 }
790 
791 const char* CBitStringDataType::GetDefaultCType(void) const
792 {
793  return "NCBI_NS_NCBI::CBitString";
794 }
795 
796 const char* CBitStringDataType::GetXMLContents(void) const
797 {
798  return DTDEntitiesEnabled() ? "%BITS;" : "#PCDATA";
799 }
800 
802 {
803 #if _DATATOOL_USE_SCHEMA_STYLE_COMMENTS
805  out << ">";
806  }
807 #else
808  out << ">";
809 #endif
810  PrintASNNewLine(out,indent++) << "<xs:simpleType>";
811  PrintASNNewLine(out,indent++) << "<xs:restriction base=\"xs:string\">";
812  PrintASNNewLine(out,indent) << "<xs:pattern value=\"([0-1])*\"/>";
813  PrintASNNewLine(out,--indent) << "</xs:restriction>";
814  PrintASNNewLine(out,--indent) << "</xs:simpleType>";
815  return true;
816 }
817 
818 const char* COctetStringDataType::GetASNKeyword(void) const
819 {
820  return "OCTET STRING";
821 }
822 
823 const char* COctetStringDataType::GetDEFKeyword(void) const
824 {
825  return "_OCTET_STRING_";
826 }
827 
829 {
830  if (x_AsBitString()) {
832  }
833  return "NCBI_NS_STD::vector<char>";
834 }
835 
837 {
838  return DTDEntitiesEnabled() ? "%OCTETS;" : "#PCDATA";
839 }
840 
842 {
843  return "xs:hexBinary";
844 }
845 
847 {
848  CheckValueType(value, COctetStringDataType, "OCTET STRING");
849  return true;
850 }
851 
853 {
854  if (x_AsBitString()) {
856  }
858  if ( HaveModuleName() )
859  return UpdateModuleName(CStdTypeInfo<vector<char> >::CreateTypeInfo());
861 }
862 
864 {
865  return true;
866 }
867 
869 {
870  if (x_AsBitString()) {
872  }
873  string charType = GetVar("_char");
874  if ( charType.empty() )
875  charType = "char";
877  charType, GetNamespaceName(), this, Comments()));
878 }
879 
881 {
882  return x_AsBitString();
883 }
884 
886 {
887  string type = GetVar("_type");
888  return NStr::FindNoCase(type, "CBitString") != NPOS;
889 }
890 
892 {
893  return "xs:base64Binary";
894 }
895 
897 {
898  return true;
899 }
900 
902 {
903  return false;
904 }
905 
907 {
908  ForbidVar("_type", "string");
909 }
910 
911 const char* CIntDataType::GetASNKeyword(void) const
912 {
913  return "INTEGER";
914 }
915 
916 const char* CIntDataType::GetDEFKeyword(void) const
917 {
918  return "_INTEGER_";
919 }
920 
921 const char* CIntDataType::GetXMLContents(void) const
922 {
923  return DTDEntitiesEnabled() ? "%INTEGER;" : "#PCDATA";
924 }
925 
927 {
928  return "xs:integer";
929 }
930 
932 {
933  CheckValueType(value, CIntDataValue, "INTEGER");
934  return true;
935 }
936 
938 {
939  return new Int8((Int8)dynamic_cast<const CIntDataValue&>(value).GetValue());
940 }
941 
943 {
944  return NStr::Int8ToString(dynamic_cast<const CIntDataValue&>(value).GetValue());
945 }
946 
948 {
949  if ( HaveModuleName() )
952 }
953 
954 const char* CIntDataType::GetDefaultCType(void) const
955 {
956  return "int";
957 }
958 
959 const char* CBigIntDataType::GetASNKeyword(void) const
960 {
961  return "BigInt";
962 }
963 
964 const char* CBigIntDataType::GetDEFKeyword(void) const
965 {
966  return "_BigInt_";
967 }
968 
969 const char* CBigIntDataType::GetXMLContents(void) const
970 {
971  return DTDEntitiesEnabled() ? "%INTEGER;" : "#PCDATA";
972 }
973 
975 {
976  return "xs:long";
977 }
978 
980 {
981  CheckValueType(value, CIntDataValue, "BigInt");
982  return true;
983 }
984 
986 {
987  return new Int8(dynamic_cast<const CIntDataValue&>(value).GetValue());
988 }
989 
991 {
992  return NStr::Int8ToString(dynamic_cast<const CIntDataValue&>(value).GetValue());
993 }
994 
996 {
997  if ( HaveModuleName() )
1000 }
1001 
1002 const char* CBigIntDataType::GetDefaultCType(void) const
1003 {
1004  return "Int8";
1005 }
1006 
1008 {
1010  if (m_bAsnBigInt) {
1011  a->SetSpecialRef("BigInt, ()");
1012  }
1013  return a;
1014 }
1015 
1016 bool CAnyContentDataType::CheckValue(const CDataValue& /* value */) const
1017 {
1018  return true;
1019 }
1020 
1021 void CAnyContentDataType::PrintASN(CNcbiOstream& out, int /* indent */) const
1022 {
1023  PrintASNTag(out);
1024  out << GetASNKeyword();
1025 }
1026 
1027 void CAnyContentDataType::PrintJSONSchema(CNcbiOstream&, int, list<string>&, bool) const
1028 {
1029 }
1030 
1031 void CAnyContentDataType::PrintXMLSchema(CNcbiOstream& out, int indent, bool contents_only) const
1032 {
1033  const CDataMember* mem = GetDataMember();
1034  if (mem) {
1035  PrintASNNewLine(out,indent) << "<xs:any processContents=\"lax\"";
1036  const string& ns = GetNamespaceName();
1037  if (!ns.empty()) {
1038  out << " namespace=\"" << ns << "\"";
1039  }
1040  if (mem->Optional()) {
1041  out << " minOccurs=\"0\"";
1042  }
1043  out << "/>";
1044  } else {
1045  if (!contents_only) {
1046  PrintASNNewLine(out,indent++) <<
1047  "<xs:element name=\"" << XmlTagName() << "\">";
1048  }
1049  PrintASNNewLine(out,indent++) << "<xs:complexType>";
1050  PrintASNNewLine(out,indent++) << "<xs:sequence>";
1051  PrintASNNewLine(out,indent) << "<xs:any processContents=\"lax\"/>";
1052  PrintASNNewLine(out,--indent) << "</xs:sequence>";
1053  PrintASNNewLine(out,--indent) << "</xs:complexType>";
1054  if (!contents_only) {
1055  PrintASNNewLine(out,--indent) << "</xs:element>";
1056  }
1057  }
1058 }
1059 
1061 {
1062  if (!contents_only) {
1063  out << "\n<!ELEMENT " << XmlTagName() << " ";
1064  }
1065  out << GetXMLContents();
1066  if (!contents_only) {
1067  out << ">";
1068  }
1069 }
1070 
1072 {
1073 #if 0
1074  return new (string*)(new string(dynamic_cast<const CStringDataValue&>(value).GetValue()));
1075 #else
1076  return (new string(dynamic_cast<const CStringDataValue&>(value).GetValue()));
1077 #endif
1078 }
1079 
1081 {
1082 // TO BE CHANGED ?!!
1083  string type = GetAndVerifyVar("_type");
1084  bool full_ns = !type.empty();
1085  if ( type.empty() )
1086  type = GetDefaultCType();
1088 }
1089 
1091 {
1092  return "NCBI_NS_NCBI::CAnyContentObject";
1093 }
1094 
1095 const char* CAnyContentDataType::GetASNKeyword(void) const
1096 {
1097 // not exactly, but...
1098 // (ASN.1 does not seem to support this type of data)
1099  return "VisibleString";
1100 }
1101 
1102 const char* CAnyContentDataType::GetDEFKeyword(void) const
1103 {
1104  return "_AnyContent_";
1105 }
1106 
1108 {
1109  return "ANY";
1110 }
1111 
virtual void PrintDTDElement(CNcbiOstream &out, bool contents_only=false) const override
virtual void PrintASN(CNcbiOstream &out, int indent) const override
virtual bool CheckValue(const CDataValue &value) const override
virtual const char * GetDEFKeyword(void) const override
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
virtual void PrintXMLSchema(CNcbiOstream &out, int indent, bool contents_only=false) const override
virtual void PrintJSONSchema(CNcbiOstream &out, int indent, list< string > &required, bool contents_only=false) const override
virtual const char * GetXMLContents(void) const override
virtual const char * GetASNKeyword(void) const override
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
virtual const char * GetDefaultCType(void) const override
virtual string GetSchemaTypeString(void) const override
Definition: statictype.cpp:891
virtual bool IsCompressed(void) const override
Definition: statictype.cpp:896
virtual bool x_AsBitString(void) const override
Definition: statictype.cpp:901
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:959
virtual string GetDefaultString(const CDataValue &value) const override
Definition: statictype.cpp:990
virtual string GetSchemaTypeString(void) const override
Definition: statictype.cpp:974
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:964
virtual CTypeRef GetTypeInfo(void) override
Definition: statictype.cpp:995
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: statictype.cpp:985
virtual const char * GetDefaultCType(void) const override
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:969
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:979
virtual bool NeedAutoPointer(const CTypeInfo *typeInfo) const override
Definition: statictype.cpp:780
CDataType * m_BitStringEnum
Definition: statictype.hpp:164
CBitStringDataType(CDataType *bitenum=nullptr)
Definition: statictype.cpp:755
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:767
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:796
virtual const char * GetDefaultCType(void) const override
Definition: statictype.cpp:791
virtual bool PrintXMLSchemaContents(CNcbiOstream &out, int indent, const CDataMember *mem) const override
Definition: statictype.cpp:801
virtual const CTypeInfo * GetRealTypeInfo(void) override
Definition: statictype.cpp:773
virtual void FixTypeTree(void) const override
Definition: statictype.cpp:760
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:745
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:750
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
Definition: statictype.cpp:785
TValues & GetValues(void)
Definition: value.hpp:177
virtual CTypeRef GetTypeInfo(void) override
Definition: statictype.cpp:491
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:387
virtual string GetSchemaTypeString(void) const override
Definition: statictype.cpp:398
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:392
virtual const char * GetDefaultCType(void) const override
Definition: statictype.cpp:498
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: statictype.cpp:480
virtual void PrintDTDExtra(CNcbiOstream &out) const override
Definition: statictype.cpp:456
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:474
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:382
virtual string GetDefaultString(const CDataValue &value) const override
Definition: statictype.cpp:485
virtual bool PrintXMLSchemaContents(CNcbiOstream &out, int indent, const CDataMember *mem) const override
Definition: statictype.cpp:411
bool PrintSchemaComments(CNcbiOstream &out, int indent, int flags=0) const
Definition: comments.cpp:91
bool Optional(void) const
Definition: blocktype.hpp:68
const string & GetName(void) const
Definition: blocktype.hpp:56
const CDataValue * GetDefault(void) const
Definition: blocktype.hpp:88
const CComments & GetComments(void) const
Definition: blocktype.hpp:109
bool SimpleType(void) const
Definition: blocktype.hpp:84
const list< CMemberFacet > & GetRestrictions(void) const
Definition: blocktype.hpp:116
const list< CMemberFacet > & GetRestrictions(void) const
Definition: type.hpp:444
EGlobalType GetGlobalType(void) const
Definition: type.hpp:431
const CDataMember * GetDataMember(void) const
Definition: type.hpp:307
CNcbiOstream & PrintASNTag(CNcbiOstream &out) const
Definition: type.cpp:123
void * TObjectPtr
Definition: type.hpp:158
bool HaveModuleName(void) const
Definition: type.hpp:173
CComments & Comments(void)
Definition: type.hpp:294
virtual AutoPtr< CTypeStrings > GetFullCType(void) const
Definition: type.cpp:872
void SetParent(const CDataType *parent, const string &memberName, string xmlName=kEmptyStr)
Definition: type.cpp:296
@ eElement
Definition: type.hpp:424
@ eType
Definition: type.hpp:425
const string & GetNamespaceName(void) const
Definition: type.hpp:403
void ForbidVar(const string &var, const string &value)
Definition: type.cpp:392
static bool DTDEntitiesEnabled(void)
Definition: type.hpp:370
virtual const char * GetASNKeyword(void) const
Definition: type.cpp:183
const CDataType * GetParentType(void) const
Definition: type.hpp:164
virtual CTypeRef GetTypeInfo(void)
Definition: type.cpp:734
CTypeInfo * UpdateModuleName(CTypeInfo *typeInfo) const
Definition: type.cpp:786
virtual string GetSchemaTypeString(void) const
Definition: type.cpp:212
ENsQualifiedMode IsNsQualified(void) const
Definition: type.hpp:411
virtual CTypeInfo * CreateTypeInfo(void)
Definition: type.cpp:780
bool IsNillable(void) const
Definition: type.hpp:419
const string GetVar(const string &value, int collect=0) const
Definition: type.cpp:340
const CDataTypeModule * GetModule(void) const
Definition: type.hpp:168
static bool IsASNDataSpec(void)
Definition: type.hpp:386
string XmlTagName(void) const
Definition: type.cpp:462
const string GetAndVerifyVar(const string &value) const
Definition: type.cpp:419
const string & GetMemberName(void) const
Definition: type.hpp:394
const TValueType & GetValue(void) const
Definition: value.hpp:98
virtual string GetXmlString(void) const =0
virtual CTypeRef GetTypeInfo(void) override
Definition: statictype.cpp:947
virtual string GetDefaultString(const CDataValue &value) const override
Definition: statictype.cpp:942
virtual string GetSchemaTypeString(void) const override
Definition: statictype.cpp:926
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:916
CIntDataType(void)
Definition: statictype.cpp:906
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: statictype.cpp:937
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:921
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:911
virtual const char * GetDefaultCType(void) const override
Definition: statictype.cpp:954
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:931
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:329
virtual const char * GetDefaultCType(void) const override
Definition: statictype.cpp:377
virtual bool PrintXMLSchemaContents(CNcbiOstream &out, int indent, const CDataMember *mem) const override
Definition: statictype.cpp:334
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:319
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: statictype.cpp:359
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
Definition: statictype.cpp:372
virtual CTypeRef GetTypeInfo(void) override
Definition: statictype.cpp:365
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:353
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:324
virtual const CTypeInfo * GetRealTypeInfo(void) override
Definition: statictype.cpp:852
virtual bool x_AsBitString(void) const
Definition: statictype.cpp:885
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:846
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:823
virtual bool NeedAutoPointer(const CTypeInfo *typeInfo) const override
Definition: statictype.cpp:863
virtual string GetSchemaTypeString(void) const override
Definition: statictype.cpp:841
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
Definition: statictype.cpp:868
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:818
virtual const char * GetDefaultCType(void) const override
Definition: statictype.cpp:828
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:836
virtual bool IsCompressed(void) const
Definition: statictype.cpp:880
virtual string GetSchemaTypeString(void) const override
Definition: statictype.cpp:523
virtual string GetDefaultString(const CDataValue &value) const override
Definition: statictype.cpp:561
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:508
CRealDataType(void)
Definition: statictype.cpp:503
virtual const char * GetDefaultCType(void) const override
Definition: statictype.cpp:585
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:518
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:513
virtual const CTypeInfo * GetRealTypeInfo(void) override
Definition: statictype.cpp:578
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:528
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: statictype.cpp:546
virtual void PrintASN(CNcbiOstream &out, int indent) const override
Definition: statictype.cpp:57
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: statictype.cpp:51
virtual const char * GetXMLContents(void) const =0
virtual void PrintXMLSchema(CNcbiOstream &out, int indent, bool contents_only=false) const override
Definition: statictype.cpp:142
virtual void PrintDTDElement(CNcbiOstream &out, bool contents_only=false) const override
Definition: statictype.cpp:260
virtual const char * GetDefaultCType(void) const =0
virtual void PrintJSONSchema(CNcbiOstream &out, int indent, list< string > &required, bool contents_only=false) const override
Definition: statictype.cpp:63
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
Definition: statictype.cpp:300
virtual bool PrintXMLSchemaContents(CNcbiOstream &out, int indent, const CDataMember *mem) const
Definition: statictype.cpp:250
virtual const CTypeInfo * GetRealTypeInfo(void) override
Definition: statictype.cpp:677
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: statictype.cpp:634
virtual const char * GetXMLContents(void) const override
Definition: statictype.cpp:618
virtual const char * GetDefaultCType(void) const override
Definition: statictype.cpp:704
virtual string GetSchemaTypeString(void) const override
Definition: statictype.cpp:623
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:602
virtual bool NeedAutoPointer(const CTypeInfo *typeInfo) const override
Definition: statictype.cpp:686
virtual string GetDefaultString(const CDataValue &value) const override
Definition: statictype.cpp:651
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
Definition: statictype.cpp:691
virtual bool CheckValue(const CDataValue &value) const override
Definition: statictype.cpp:628
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:610
CStringDataType(EType type=eStringTypeVisible)
Definition: statictype.cpp:590
virtual const char * GetASNKeyword(void) const override
Definition: statictype.cpp:716
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
Definition: statictype.cpp:736
virtual bool NeedAutoPointer(const CTypeInfo *typeInfo) const override
Definition: statictype.cpp:731
virtual const CTypeInfo * GetRealTypeInfo(void) override
Definition: statictype.cpp:726
virtual const char * GetDEFKeyword(void) const override
Definition: statictype.cpp:721
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
int close(int fd)
Definition: connection.cpp:45
std::ofstream out("events_result.xml")
main entry point for tests
#define bool
Definition: bool.h:34
static int type
Definition: getdata.c:31
static FILE * f
Definition: readconf.c:23
element_type * release(void)
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:472
#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
@ eNSQualified
Definition: serialdef.hpp:201
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
Definition: ncbistr.hpp:5153
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
Definition: ncbistr.hpp:5181
#define kEmptyStr
Definition: ncbistr.hpp:123
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
Definition: ncbistr.cpp:2984
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5424
#define NPOS
Definition: ncbistr.hpp:133
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3883
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
@ fDoubleGeneral
Definition: ncbistr.hpp:258
@ fDoublePosix
DoubleToString*(): Use C locale for double conversions.
Definition: ncbistr.hpp:257
int i
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
unsigned int a
Definition: ncbi_localip.c:102
Common macro to detect used sanitizers and suppress memory leaks if run under LeakSanitizer.
#define NCBI_LSAN_DISABLE_GUARD
const char * tag
string indent(" ")
CNcbiOstream & PrintASNNewLine(CNcbiOstream &out, int indent)
Definition: srcutil.cpp:130
Definition: type.c:6
#define CheckValueType(value, type, name)
Definition: type.hpp:499
Modified on Fri Sep 20 14:57:09 2024 by modify_doxy.py rev. 669887