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

Go to the SVN repository for this file.

1 /* $Id: type.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 * Base class for type description
30 */
31 
32 #include <ncbi_pch.hpp>
33 #include "type.hpp"
36 #include "value.hpp"
37 #include "blocktype.hpp"
38 #include "module.hpp"
39 #include "classstr.hpp"
40 #include "aliasstr.hpp"
41 #include "exceptions.hpp"
42 #include "reftype.hpp"
43 #include "unitype.hpp"
44 #include "choicetype.hpp"
45 #include "statictype.hpp"
46 #include "enumtype.hpp"
47 #include "fileutil.hpp"
48 #include "srcutil.hpp"
49 #include "datatool.hpp"
50 #include <serial/error_codes.hpp>
51 #include <algorithm>
52 #include <common/ncbi_sanitizers.h>
53 
54 
55 #define NCBI_USE_ERRCODE_X Serial_DTType
56 
58 
59 
61 bool CDataType::sm_EnforcedStdXml = false;
66 
68 {
69 public:
71  : m_Type(type)
72  {
73  }
74 
75  virtual TTypeInfo GetTypeInfo(void) override;
76 
77 private:
79 };
80 
82 {
84  return m_Type->GetAnyTypeInfo();
85 }
86 
88  : m_ParentType(0), m_Module(0), m_SourceLine(0),
89  m_DataMember(0), m_TypeStr(0), m_Set(0), m_Choice(0), m_Checked(false),
90  m_Tag(eNoExplicitTag), m_TagClass(CAsnBinaryDefs::eUniversal),
91  m_TagType(CAsnBinaryDefs::eAutomatic),
92  m_IsAlias(false), m_IsTypeAlias(false), m_NsQualified(eNSQNotSet), m_IsNillable(false),
93  m_GlobalType(eElement), m_EmptyExternalName(false)
94 {
95 }
96 
98 {
99 // NOTE: This compiler bug was fixed by Jan 24 2002, test passed with:
100 // CC: Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-03 2001/10/19
101 // We leave the workaround here for maybe half a year (for other guys).
102 #if defined(NCBI_COMPILER_WORKSHOP)
103 // We have to use two #if's here because KAI C++ cannot handle #if foo == bar
104 # if (NCBI_COMPILER_VERSION == 530)
105  // BW_010:: to workaround (already reported to SUN, CASE ID 62563729)
106  // internal bug of the SUN Forte 6 Update 1 and Update 2 compiler
107  (void) atoi("5");
108 # endif
109 #endif
110 }
111 
113 {
114  m_SourceLine = line;
115 }
116 
117 void CDataType::Warning(const string& mess, int err_subcode) const
118 {
119  CNcbiDiag() << ErrCode(NCBI_ERRCODE_X, err_subcode)
120  << LocationString() << ": " << mess;
121 }
122 
124 {
125  if (HasTag()) {
126  out << '[';
127  switch (GetTagClass()) {
128  default: break;
129  case CAsnBinaryDefs::eApplication: out << "APPLICATION "; break;
130  case CAsnBinaryDefs::ePrivate: out << "PRIVATE "; break;
131  }
133  out << ']';
135  if (ttype != GetModule()->GetTagDefault()) {
136  switch (ttype) {
137  default: break;
138  case CAsnBinaryDefs::eExplicit: out << " EXPLICIT"; break;
139  case CAsnBinaryDefs::eImplicit: out << " IMPLICIT"; break;
140  }
141  }
142  out << ' ';
143  }
144  return out;
145 }
146 
148 {
149  const char* p = "something went wrong";
150  switch (tclass) {
151  default:
152  break;
153  case CAsnBinaryDefs::eUniversal: p = "ncbi::CAsnBinaryDefs::eUniversal"; break;
154  case CAsnBinaryDefs::eApplication: p = "ncbi::CAsnBinaryDefs::eApplication"; break;
155  case CAsnBinaryDefs::eContextSpecific: p = "ncbi::CAsnBinaryDefs::eContextSpecific"; break;
156  case CAsnBinaryDefs::ePrivate: p = "ncbi::CAsnBinaryDefs::ePrivate"; break;
157  }
158  return p;
159 }
161 {
162  const char* p = "something went wrong";
163  switch (ttype) {
164  default:
165  break;
166  case CAsnBinaryDefs::eExplicit: p = "ncbi::CAsnBinaryDefs::eExplicit"; break;
167  case CAsnBinaryDefs::eImplicit: p = "ncbi::CAsnBinaryDefs::eImplicit"; break;
168  }
169  return p;
170 }
171 
173  int indent, int flags) const
174 {
176 }
177 
179 {
181 }
182 
183 const char* CDataType::GetASNKeyword(void) const
184 {
185  return "";
186 }
187 
189 {
190  if (!GetParentType()) {
192  out << 'T' << ',' <<
193  GetSourceLine() <<",";
194  out << GetFullName() << ',' << GetSpecKeyword();
196  }
198  if (!GetParentType()) {
200  }
201 }
202 
203 void CDataType::PrintSpecDumpExtra(CNcbiOstream& /*out*/, int /*indent*/) const
204 {
205 }
206 
207 string CDataType::GetSpecKeyword(void) const
208 {
209  return GetASNKeyword();
210 }
211 
213 {
214  return kEmptyStr;
215 }
216 
218 {
219  if (x_IsSavedName(XmlTagName())) {
220  return;
221  }
222  out << "\n\n";
227 }
228 
230  const CComments& extra) const
231 {
232  if (m_DataMember && (m_DataMember->Attlist() || m_DataMember->Notag())) {
233  return;
234  }
235  if (x_IsSavedName(XmlTagName())) {
236  return;
237  }
238  out << "\n";
239  if (IsReference() && extra.Empty()) {
240  const CDataType* realType = Resolve();
241  if (realType && realType != this) {
243  }
244  }
250 }
251 
253 {
254 }
255 
257 {
258  _ASSERT(GetParentType() == sequence);
259  m_Set = sequence;
260 }
261 
263 {
264  _ASSERT(GetParentType() == choice);
265  m_Choice = choice;
266 }
267 
269 {
270  _ASSERT(GetParentType() == 0 || reference->IsRefToParent());
271  if ( !m_References )
273  m_References->push_back(reference);
274 }
275 
276 bool CDataType::IsInUniSeq(void) const
277 {
278  return dynamic_cast<const CUniSequenceDataType*>(GetParentType()) != 0;
279 }
280 
281 bool CDataType::IsUniSeq(void) const
282 {
283  return dynamic_cast<const CUniSequenceDataType*>(this) != 0;
284 }
285 
286 bool CDataType::IsContainer(void) const
287 {
288  return dynamic_cast<const CDataMemberContainerType*>(this) != 0;
289 }
290 
291 bool CDataType::IsEnumType(void) const
292 {
293  return dynamic_cast<const CEnumDataType*>(this) != 0;
294 }
295 
296 void CDataType::SetParent(const CDataType* parent, const string& memberName,
297  string xmlName)
298 {
299  _ASSERT(parent != 0);
300  _ASSERT(m_ParentType == 0 && m_Module == 0 && m_MemberName.empty());
301  m_ParentType = parent;
302  m_Module = parent->GetModule();
303  x_SetMemberAndClassName( memberName);
304  m_XmlName = xmlName;
305  _ASSERT(m_Module != 0);
308  }
309  FixTypeTree();
310 }
311 
313  const string& typeName)
314 {
315  _ASSERT(module != 0);
316  _ASSERT(m_ParentType == 0 && m_Module == 0 && m_MemberName.empty());
317  m_Module = module;
318  x_SetMemberAndClassName( typeName );
319  FixTypeTree();
320 }
321 
322 void CDataType::FixTypeTree(void) const
323 {
324 }
325 
327 {
328  if ( m_Checked )
329  return true;
330  m_Checked = true;
331  _ASSERT(m_Module != 0);
332  return CheckType();
333 }
334 
335 bool CDataType::CheckType(void) const
336 {
337  return true;
338 }
339 
340 const string CDataType::GetVar(const string& varName, int collect /*= 0*/) const
341 {
342  if ( !((CDataTool*)CNcbiApplication::Instance())->HasConfig() &&
344  return kEmptyStr;
345  }
346  const CDataType* parent = GetParentType();
347  if (collect >=0 && GetDataMember()) {
348 #if 0
349  collect = GetDataMember()->Notag() ? 1 : 0;
350 #else
351  collect = GetDataMember()->GetType()->IsPrimitive() ? -1 : 1;
352 #endif
353  }
354  if ( !parent ) {
355  return GetModule()->GetVar(m_MemberName, varName, collect > 0);
356  }
357  else {
358  string s;
359  if (IsUniSeq() && m_MemberName == parent->GetMemberName()) {
360  s = parent->GetVar(varName, collect);
361  } else {
362  s = parent->GetVar(m_MemberName + '.' + varName, collect);
363  }
364  if (!s.empty()) {
365  return s;
366  }
367  s = string(GetDEFKeyword()) + '.' + varName;
368  return parent->GetVar(s, -1);
369  }
370 }
371 
372 bool CDataType::GetBoolVar(const string& varName, bool default_value) const
373 {
374  string value = GetVar(varName);
376  if ( value.empty() ) {
377  return default_value;
378  }
379  try {
380  return NStr::StringToBool(value);
381  }
382  catch ( CException& /*ignored*/ ) {
383  }
384  try {
385  return NStr::StringToInt(value) != 0;
386  }
387  catch ( CException& /*ignored*/ ) {
388  }
389  return default_value;
390 }
391 
392 void CDataType::ForbidVar(const string& var, const string& value)
393 {
394  typedef multimap<string, string> TMultimap;
395  if (!var.empty() && !value.empty()) {
396  TMultimap::const_iterator it = m_ForbidVar.find(var);
397  for ( ; it != m_ForbidVar.end() && it->first == var; ++it) {
398  if (it->second == value) {
399  return;
400  }
401  }
403  }
404 }
405 
406 void CDataType::AllowVar(const string& var, const string& value)
407 {
408  if (!var.empty() && !value.empty()) {
410  for ( ; it != m_ForbidVar.end() && it->first == var; ++it) {
411  if (it->second == value) {
412  m_ForbidVar.erase(it);
413  return;
414  }
415  }
416  }
417 }
418 
419 const string CDataType::GetAndVerifyVar(const string& var) const
420 {
421  const string tmp = GetVar(var);
422  if (!tmp.empty()) {
424  for ( ; it != m_ForbidVar.end() && it->first == var; ++it) {
425  if (it->second == tmp) {
427  IdName()+": forbidden "+var+"="+tmp);
428  }
429  }
430  }
431  return tmp;
432 }
433 
434 const string& CDataType::GetSourceFileName(void) const
435 {
436  if (m_Module) {
437  return GetModule()->GetSourceFileName();
438  } else {
439  return kEmptyStr;
440  }
441 }
442 
443 string CDataType::LocationString(void) const
444 {
446  ": " + IdName();
447 }
448 
449 string CDataType::IdName(void) const
450 {
451  const CDataType* parent = GetParentType();
452  if ( !parent ) {
453  // root type
454  return m_MemberName;
455  }
456  else {
457  // member
458  return parent->IdName() + '.' + m_MemberName;
459  }
460 }
461 
462 string CDataType::XmlTagName(void) const
463 {
464  if (GetEnforcedStdXml()) {
465  return m_MemberName;
466  }
467  const CDataType* parent = GetParentType();
468  if ( !parent ) {
469  // root type
470  return m_MemberName;
471  }
472  else {
473  // member
474  return parent->XmlTagName() + '_' +
475  (m_XmlName.empty() ? m_MemberName : m_XmlName);
476  }
477 }
478 
479 const string& CDataType::GlobalName(void) const
480 {
481  if ( !GetParentType() ) {
482  return m_MemberName;
483  } else {
484  const CDataMember* m = GetDataMember();
485  if (!m) {
486  const CUniSequenceDataType* seq =
487  dynamic_cast<const CUniSequenceDataType*>(GetParentType());
488  if (seq) {
489  m = seq->GetDataMember();
490  }
491  }
492  if (m && !IsASNDataSpec() && !m->Attlist() && !m->Notag()) {
493  m = GetParentType()->GetDataMember();
494  if (!m) {
495  return GetDataMember()->GetName();
496  } else if (!IsASNDataSpec() && !m->Attlist()) {
497  if (IsInUniSeq()) {
498  return m->GetName();
499  } else {
500  return m_MemberName;
501  }
502  }
503  }
504  return NcbiEmptyString;
505  }
506 }
507 
508 string CDataType::GetKeyPrefix(void) const
509 {
510  const CDataType* parent = GetParentType();
511  if ( !parent ) {
512  // root type
513  return NcbiEmptyString;
514  }
515  else {
516  // member
517  string parentPrefix = parent->GetKeyPrefix();
518  if ( parentPrefix.empty() )
519  return m_MemberName;
520  else
521  return parentPrefix + '.' + m_MemberName;
522  }
523 }
524 
525 bool CDataType::Skipped(void) const
526 {
527  return GetVar("_class") == "-";
528 }
529 
531 {
532  string cls;
533  // only for local types
534  if ( GetParentType() ) {
535  cls = GetVar("_class");
536  if ( !cls.empty() ) {
537  if (cls[0] == 'C') {
538  cls.erase(0,1);
539  }
540  if (cls[0]=='_') {
541  cls.erase(0,1);
542  }
543  }
544  }
545  return cls;
546 }
547 
548 void CDataType::x_SetMemberAndClassName(const string& memberName)
549 {
550  m_MemberName = memberName;
551 
552  if ( GetParentType() ) {
553  // local type
554  if ( m_MemberName == "E" ) {
555  m_ClassName = "E";
556  for ( const CDataType* type = GetParentType(); type; type = type->GetParentType() ) {
557  const CDataType* parent = type->GetParentType();
558  if ( !parent )
559  break;
560  if ( dynamic_cast<const CDataMemberContainerType*>(parent) ) {
561  m_ClassName += "_";
562  m_ClassName += Identifier(type->m_MemberName);
563  break;
564  }
565  }
566  m_ClassName = "C_" + m_ClassName;
567  }
568  else {
570  }
571 
572  const CDataType* parent = GetParentType();
573  if (parent->IsUniSeq()) {
574  parent = parent->GetParentType();
575  }
576  if (parent && parent->m_ClassName == m_ClassName) {
577  m_ClassName += '_';
578  }
579  }
580 }
581 
582 string CDataType::ClassName(void) const
583 {
584  const string cls = GetVar("_class");
585  if ( !cls.empty() )
586  return cls;
587  if ( GetParentType() ) {
588  // local type
589 // return "C_"+Identifier(m_MemberName);
590  return m_ClassName;
591  }
592  else {
593  // global type
594 #if 0
595  return 'C'+Identifier(m_MemberName);
596 #else
597  string g;
598  for (size_t i=0;;++i) {
599  g.assign(1,'C').append(i,'_').append(Identifier(m_MemberName));
602  } else {
603  if ( sm_ClassToMember[g] != m_MemberName) {
604  continue;
605  }
606  }
607  return g;
608  }
609 #endif
610  }
611 }
612 
613 string CDataType::FileName(void) const
614 {
615  if ( GetParentType() ) {
616  return GetParentType()->FileName();
617  }
618  if ( m_CachedFileName.empty() ) {
619  string prefix(GetModule()->GetSubnamespace());
620  if (!prefix.empty()) {
621  prefix += '_';
622  }
623  const string file = GetVar("_file");
624  if ( !file.empty() ) {
626  }
627  else {
628  string dir = GetVar("_dir");
629  if ( dir.empty() ) {
630  _ASSERT(!GetParentType()); // for non internal classes
631  dir = GetModule()->GetFileNamePrefix();
632  }
634  Path(dir,
635  MakeFileName(prefix+m_MemberName, 5 /* strlen("_.cpp") */ ));
636 
637  // verify that this name is not used already
639  string tmp(m_CachedFileName);
640  while (sm_AllFileNames.find(tmp) != sm_AllFileNames.end()) {
641  string::size_type p = tmp.find_last_not_of('x');
642  if (p == 0) {
643  tmp.clear();
644  break;
645  }
646  if (p != string::npos) {
647  tmp[p] = 'x';
648  }
649  }
650  if (tmp.empty()) {
652  while (sm_AllFileNames.find(tmp) != sm_AllFileNames.end()) {
653  tmp.append(1,'x');
654  }
655  }
657  }
658  }
659  if (!IsPrimitive()) {
661  }
662  }
663  return m_CachedFileName;
664 }
665 
667 {
668  if ( !m_CachedNamespace.get() ) {
669  const string ns = GetVar("_namespace");
670  if ( !ns.empty() ) {
671  string sub_ns(GetModule()->GetSubnamespace());
672  if (sub_ns.empty()) {
673  m_CachedNamespace.reset(new CNamespace(ns));
674  } else {
675  m_CachedNamespace.reset(new CNamespace(ns + "::" + sub_ns));
676  }
677  }
678  else {
679  if ( GetParentType() ) {
680  return GetParentType()->Namespace();
681  }
682  else {
683  return GetModule()->GetNamespace();
684  }
685  }
686  }
687  return *m_CachedNamespace;
688 }
689 
690 string CDataType::InheritFromClass(void) const
691 {
692  return GetVar("_parent_class");
693 }
694 
696 {
697  const string parentName = GetVar("_parent_type");
698  if ( !parentName.empty() )
699  return ResolveGlobal(parentName);
700  return 0;
701 }
702 
704 {
705  return this;
706 }
707 
708 const CDataType* CDataType::Resolve(void) const
709 {
710  return this;
711 }
712 
713 CDataType* CDataType::ResolveLocal(const string& name) const
714 {
715  return GetModule()->Resolve(name);
716 }
717 
718 CDataType* CDataType::ResolveGlobal(const string& name) const
719 {
720  SIZE_TYPE dot = name.find('.');
721  if ( dot == NPOS ) {
722  // no module specified
723  return GetModule()->Resolve(name);
724  }
725  else {
726  // resolve by module
727  string moduleName = name.substr(0, dot);
728  string typeName = name.substr(dot + 1);
729  return GetModule()->GetModuleContainer().InternalResolve(moduleName,
730  typeName);
731  }
732 }
733 
735 {
736  if ( !m_TypeRef )
737  m_TypeRef = CTypeRef(new CAnyTypeSource(this));
738  return m_TypeRef;
739 }
740 
742 {
743  TTypeInfo typeInfo = m_AnyTypeInfo.get();
744  if ( !typeInfo ) {
745  typeInfo = GetRealTypeInfo();
746  const_cast<CTypeInfo*>(typeInfo)->DataSpec( CDataType::GetSourceDataSpec());
747  if ( NeedAutoPointer(typeInfo) ) {
748  if (IsAlias() && !IsStdType()) {
749  CAliasTypeInfo *alias =
750  new CAliasTypeInfo(GlobalName(),typeInfo);
751  alias->SetModuleName( typeInfo->GetModuleName());
752  if (IsTypeAlias()) {
753  alias->SetFullAlias();
754  }
755  typeInfo = alias;
756  }
759  typeInfo = m_AnyTypeInfo.get();
760  }
761  }
762  return typeInfo;
763 }
764 
766 {
767  return typeInfo->GetSize() > sizeof(AnyType);
768 }
769 
771 {
772  TTypeInfo typeInfo = m_RealTypeInfo.get();
773  if ( !typeInfo ) {
775  typeInfo = m_RealTypeInfo.get();
776  }
777  return typeInfo;
778 }
779 
781 {
782  NCBI_THROW(CDatatoolException,eIllegalCall,
783  "cannot create type info of "+IdName());
784 }
785 
787 {
788  if ( HaveModuleName() )
789  typeInfo->SetModuleName(GetModule()->GetName());
790  return typeInfo;
791 }
792 
794 {
795  if ( !IsAlias() ) {
797  ClassName(),
799  this,
800  Comments()));
802  bool nonempty = false, noprefix = false;
803  const CUniSequenceDataType* uniseq =
804  dynamic_cast<const CUniSequenceDataType*>(this);
805  if (uniseq) {
806  nonempty = uniseq->IsNonEmpty();
807  }
808  noprefix = !IsASNDataSpec();
809  code->AddMember(dType, GetTag(), nonempty, noprefix);
811  return AutoPtr<CTypeStrings>(code.release());
812  }
813  else {
814  string fullalias = GetVar("_fullalias");
817  ClassName(),
818  *dType.release(),
819  Comments()));
820  code->SetDataType(this);
821  code->SetNamespaceName( GetNamespaceName());
822  code->SetFullAlias(!fullalias.empty() || IsTypeAlias());
823  return AutoPtr<CTypeStrings>(code.release());
824  }
825 }
826 
828 {
829  const CDataType* parent = InheritFromType();
830  if ( parent ) {
831  code.SetParentClass(parent->ClassName(),
832  parent->Namespace(),
833  parent->FileName());
834  }
835  else {
836  string parentClassName = InheritFromClass();
837  if ( !parentClassName.empty() ) {
838  SIZE_TYPE pos = parentClassName.rfind("::");
839  if ( pos != NPOS ) {
840  code.SetParentClass(parentClassName.substr(pos + 2),
841  CNamespace(parentClassName.substr(0, pos)),
843  }
844  else {
845  code.SetParentClass(parentClassName,
848  }
849  }
850  }
851 }
852 
854 {
855  if ( !IsAlias() ) {
857  Namespace(),
858  FileName(),
859  Comments()));
860  }
861  else {
864  Namespace(),
865  FileName(),
866  *dType.release(),
867  Comments()));
868  return AutoPtr<CTypeStrings>(code.release());
869  }
870 }
871 
873 {
874  NCBI_THROW(CDatatoolException,eInvalidData,
875  LocationString() + ": C++ type undefined");
876 }
877 
879 {
880  Warning("Default is not supported by this type", 3);
881  return "...";
882 }
883 
884 bool CDataType::IsPrimitive(void) const
885 {
886  const CStaticDataType* st = dynamic_cast<const CStaticDataType*>(this);
887  if (st) {
888  const CBoolDataType* b = dynamic_cast<const CBoolDataType*>(this);
889  if (b) {
890  return true;
891  }
892  const CIntDataType* i = dynamic_cast<const CIntDataType*>(this);
893  if (i) {
894  return true;
895  }
896  const CRealDataType* r = dynamic_cast<const CRealDataType*>(this);
897  if (r) {
898  return true;
899  }
900  }
901  const CEnumDataType* e = dynamic_cast<const CEnumDataType*>(this);
902  if (e) {
903  return true;
904  }
905  return false;
906 }
907 
908 bool CDataType::IsStdType(void) const
909 {
910  // Primitive (except enums) or string
911  const CStaticDataType* st = dynamic_cast<const CStaticDataType*>(this);
912  if (st) {
913  const CBoolDataType* b = dynamic_cast<const CBoolDataType*>(this);
914  if (b) {
915  return true;
916  }
917  const CIntDataType* i = dynamic_cast<const CIntDataType*>(this);
918  if (i) {
919  return true;
920  }
921  const CRealDataType* r = dynamic_cast<const CRealDataType*>(this);
922  if (r) {
923  return true;
924  }
925  const COctetStringDataType* o =
926  dynamic_cast<const COctetStringDataType*>(this);
927  if (o) {
928  return true;
929  }
930  const CStringDataType* s = dynamic_cast<const CStringDataType*>(this);
931  if (s) {
932  return true;
933  }
934  }
935  return false;
936 }
937 
938 bool CDataType::IsReference(void) const
939 {
940  return dynamic_cast<const CReferenceDataType*>(this) != 0;
941 }
942 
943 bool CDataType::x_IsSavedName(const string& name)
944 {
945  return sm_EnforcedStdXml &&
946  sm_SavedNames.find(name) != sm_SavedNames.end();
947 }
948 
949 void CDataType::x_AddSavedName(const string& name)
950 {
951  if (sm_EnforcedStdXml) {
952  sm_SavedNames.insert(name);
953  }
954 }
955 
956 const char* CDataType::GetDEFKeyword(void) const
957 {
958  return "-";
959 }
960 
962 {
963  switch (sm_SourceDataSpec) {
964  case EDataSpec::eASN: return "ncbi::EDataSpec::eASN";
965  case EDataSpec::eDTD: return "ncbi::EDataSpec::eDTD";
966  case EDataSpec::eXSD: return "ncbi::EDataSpec::eXSD";
967  case EDataSpec::eJSON: return "ncbi::EDataSpec::eJSON";
968  default: break;
969  }
970  return "ncbi::EDataSpec::eUnknown";
971 }
972 
973 string CDataType::GetFullName(void) const
974 {
975  string name;
976  const CDataType* parent = GetParentType();
977  if (parent) {
978  name = parent->GetFullName();
979  if (!name.empty() && name[name.size()-1] != ':') {
980  name += ':';
981  }
982  }
983  bool notag = false;
984  if (GetDataMember()) {
985  notag = GetDataMember()->Attlist() || GetDataMember()->Notag();
986  if (GetDataMember()->Notag()) {
987  bool special=false;
988  const CDataMemberContainerType* cont =
989  dynamic_cast<const CDataMemberContainerType*>(this);
990  if (cont) {
991  special=true;
992  const CDataMemberContainerType::TMembers& members = cont->GetMembers();
993  bool hasAttlist = !members.empty() && members.front()->Attlist();
994  if (( hasAttlist && members.size() == 2) ||
995  (!hasAttlist && members.size() == 1)) {
996  const CDataMember* member = members.back().get();
997  special = !member->GetType()->IsUniSeq();
998  }
999  } else if (IsUniSeq()) {
1000  const CDataType* parent_type = GetParentType();
1001  special = parent_type->GetDataMember() != 0;
1002  if (!special && parent_type->IsContainer()) {
1003  cont = dynamic_cast<const CDataMemberContainerType*>(parent_type);
1004  special = cont->GetMembers().size() == 1;
1005  }
1006  }
1007  if (special) {
1008  name += '[' + GetMemberName() + ']';
1009  }
1010  }
1011  } else {
1012  notag = IsInUniSeq();
1013  }
1014  if (!notag) {
1015  name += GetMemberName();
1016  }
1017  return name;
1018 }
1019 
info DataSpec(ncbi::EDataSpec::eXSD)
CDataType * m_Type
Definition: type.cpp:78
virtual TTypeInfo GetTypeInfo(void) override
Definition: type.cpp:81
CAnyTypeSource(CDataType *type)
Definition: type.cpp:70
CNcbiOstream & PrintASN(CNcbiOstream &out, int indent, int flags=0) const
Definition: comments.cpp:156
bool Empty(void) const
Definition: comments.hpp:89
CNcbiOstream & PrintDTD(CNcbiOstream &out, int flags=0) const
Definition: comments.cpp:121
const TMembers & GetMembers(void) const
Definition: blocktype.hpp:155
list< AutoPtr< CDataMember > > TMembers
Definition: blocktype.hpp:137
const string & GetName(void) const
Definition: blocktype.hpp:56
const CDataValue * GetDefault(void) const
Definition: blocktype.hpp:88
CDataType * GetType(void)
Definition: blocktype.hpp:60
bool Attlist(void) const
Definition: blocktype.hpp:76
bool Notag(void) const
Definition: blocktype.hpp:80
virtual string GetFileNamePrefix(void) const override
Definition: module.cpp:558
CDataType * Resolve(const string &name) const
Definition: module.cpp:547
const string GetVar(const string &section, const string &value, bool collect) const
Definition: module.cpp:576
virtual const CNamespace & GetNamespace(void) const override
Definition: module.cpp:115
static map< string, string > sm_ClassToMember
Definition: type.hpp:496
string FileName(void) const
Definition: type.cpp:613
static string GetSourceDataSpecString(void)
Definition: type.cpp:961
void SetInSet(const CUniSequenceDataType *sequence)
Definition: type.cpp:256
void x_SetMemberAndClassName(const string &memberName)
Definition: type.cpp:548
virtual const char * GetDEFKeyword(void) const
Definition: type.cpp:956
AutoPtr< CTypeInfo > m_AnyTypeInfo
Definition: type.hpp:472
static bool x_IsSavedName(const string &name)
Definition: type.cpp:943
virtual ~CDataType(void)
Definition: type.cpp:97
CDataType * ResolveLocal(const string &name) const
Definition: type.cpp:713
void Warning(const string &mess, int err_subcode=0) const
Definition: type.cpp:117
void SetParentClassTo(CClassTypeStrings &code) const
Definition: type.cpp:827
static void x_AddSavedName(const string &name)
Definition: type.cpp:949
const CDataMember * GetDataMember(void) const
Definition: type.hpp:307
CNcbiOstream & PrintASNTag(CNcbiOstream &out) const
Definition: type.cpp:123
int m_SourceLine
Definition: type.hpp:459
virtual string GetDefaultString(const CDataValue &value) const
Definition: type.cpp:878
const CDataType * InheritFromType(void) const
Definition: type.cpp:695
int GetSourceLine(void) const
Definition: type.hpp:179
bool IsEnumType(void) const
Definition: type.cpp:291
bool HaveModuleName(void) const
Definition: type.hpp:173
CComments & Comments(void)
Definition: type.hpp:294
CAsnBinaryDefs::ETagClass GetTagClass(void) const
Definition: type.hpp:329
void PrintASNTypeComments(CNcbiOstream &out, int indent, int flags=0) const
Definition: type.cpp:172
virtual AutoPtr< CTypeStrings > GetFullCType(void) const
Definition: type.cpp:872
CTypeRef m_TypeRef
Definition: type.hpp:471
void PrintDTD(CNcbiOstream &out) const
Definition: type.cpp:217
void SetParent(const CDataType *parent, const string &memberName, string xmlName=kEmptyStr)
Definition: type.cpp:296
string m_XmlName
Definition: type.hpp:458
string LocationString(void) const
Definition: type.cpp:443
CDataType(void)
Definition: type.cpp:87
virtual bool CheckType(void) const
Definition: type.cpp:335
virtual const CTypeInfo * GetRealTypeInfo(void)
Definition: type.cpp:770
string m_CachedFileName
Definition: type.hpp:475
string GetFullName(void) const
Definition: type.cpp:973
virtual AutoPtr< CTypeStrings > GenerateCode(void) const
Definition: type.cpp:793
const string & GlobalName(void) const
Definition: type.cpp:479
string ClassName(void) const
Definition: type.cpp:582
const string & GetNamespaceName(void) const
Definition: type.hpp:403
void ForbidVar(const string &var, const string &value)
Definition: type.cpp:392
string DefClassMemberName(void) const
Definition: type.cpp:530
CDataType * ResolveGlobal(const string &name) const
Definition: type.cpp:718
void AllowVar(const string &var, const string &value)
Definition: type.cpp:406
list< const CReferenceDataType * > TReferences
Definition: type.hpp:159
virtual const char * GetASNKeyword(void) const
Definition: type.cpp:183
static string GetTagClassString(CAsnBinaryDefs::ETagClass tclass)
Definition: type.cpp:147
const CDataType * GetParentType(void) const
Definition: type.hpp:164
CAsnBinaryDefs::ETagType GetTagType(void) const
Definition: type.hpp:335
virtual void PrintDTDExtra(CNcbiOstream &out) const
Definition: type.cpp:252
const CDataType * m_ParentType
Definition: type.hpp:454
bool IsReference(void) const
Definition: type.cpp:938
virtual void PrintSpecDump(CNcbiOstream &out, int indent) const
Definition: type.cpp:188
static bool sm_EnforcedStdXml
Definition: type.hpp:493
static set< string > sm_SavedNames
Definition: type.hpp:495
const CChoiceDataType * m_Choice
Definition: type.hpp:466
virtual CTypeRef GetTypeInfo(void)
Definition: type.cpp:734
static bool sm_EnableDTDEntities
Definition: type.hpp:492
CComments m_Comments
Definition: type.hpp:460
static bool GetEnforcedStdXml(void)
Definition: type.hpp:376
const string & GetSourceFileName(void) const
Definition: type.cpp:434
static string GetTagTypeString(CAsnBinaryDefs::ETagType ttype)
Definition: type.cpp:160
void SetSourceLine(int line)
Definition: type.cpp:112
virtual void PrintDTDElement(CNcbiOstream &out, bool contents_only=false) const =0
bool IsPrimitive(void) const
Definition: type.cpp:884
CTypeInfo * UpdateModuleName(CTypeInfo *typeInfo) const
Definition: type.cpp:786
const CDataTypeModule * m_Module
Definition: type.hpp:455
bool GetBoolVar(const string &value, bool default_value=false) const
Definition: type.cpp:372
bool Skipped(void) const
Definition: type.cpp:525
virtual void FixTypeTree(void) const
Definition: type.cpp:322
void PrintDTDTypeComments(CNcbiOstream &out, int indent) const
Definition: type.cpp:178
bool Check(void)
Definition: type.cpp:326
const CUniSequenceDataType * m_Set
Definition: type.hpp:465
static set< string, PNocase > sm_AllFileNames
Definition: type.hpp:474
virtual string GetSchemaTypeString(void) const
Definition: type.cpp:212
virtual const CTypeInfo * GetAnyTypeInfo(void)
Definition: type.cpp:741
AutoPtr< TReferences > m_References
Definition: type.hpp:467
void SetInChoice(const CChoiceDataType *choice)
Definition: type.cpp:262
static EDataSpec sm_SourceDataSpec
Definition: type.hpp:494
bool m_Checked
Definition: type.hpp:469
const CNamespace & Namespace(void) const
Definition: type.cpp:666
bool IsContainer(void) const
Definition: type.cpp:286
void AddReference(const CReferenceDataType *reference)
Definition: type.cpp:268
virtual CTypeInfo * CreateTypeInfo(void)
Definition: type.cpp:780
string m_ClassName
Definition: type.hpp:457
virtual const CDataType * Resolve(void) const
Definition: type.cpp:708
string GetKeyPrefix(void) const
Definition: type.cpp:508
unique_ptr< CNamespace > m_CachedNamespace
Definition: type.hpp:476
bool IsStdType(void) const
Definition: type.cpp:908
string m_MemberName
Definition: type.hpp:456
virtual void PrintSpecDumpExtra(CNcbiOstream &out, int indent) const
Definition: type.cpp:203
string InheritFromClass(void) const
Definition: type.cpp:690
multimap< string, string > m_ForbidVar
Definition: type.hpp:482
const string GetVar(const string &value, int collect=0) const
Definition: type.cpp:340
CAsnBinaryDefs::TLongTag GetTag(void) const
Definition: type.hpp:318
virtual bool NeedAutoPointer(const CTypeInfo *typeInfo) const
Definition: type.cpp:765
bool HasTag(void) const
Definition: type.hpp:322
const CDataTypeModule * GetModule(void) const
Definition: type.hpp:168
CDataMember * m_DataMember
Definition: type.hpp:461
static bool IsASNDataSpec(void)
Definition: type.hpp:386
bool IsInUniSeq(void) const
Definition: type.cpp:276
string XmlTagName(void) const
Definition: type.cpp:462
AutoPtr< CTypeInfo > m_RealTypeInfo
Definition: type.hpp:473
virtual AutoPtr< CTypeStrings > GetRefCType(void) const
Definition: type.cpp:853
const string GetAndVerifyVar(const string &value) const
Definition: type.cpp:419
bool IsTypeAlias(void) const
Definition: type.hpp:363
bool IsUniSeq(void) const
Definition: type.cpp:281
virtual string GetSpecKeyword(void) const
Definition: type.cpp:207
static EDataSpec GetSourceDataSpec(void)
Definition: type.hpp:382
bool IsAlias(void) const
Definition: type.hpp:356
const string & GetMemberName(void) const
Definition: type.hpp:394
string IdName(void) const
Definition: type.cpp:449
void SetModule(const CDataTypeModule *module) const
Definition: value.cpp:54
virtual CDataType * InternalResolve(const string &moduleName, const string &typeName) const
Definition: mcontainer.cpp:84
const CModuleContainer & GetModuleContainer(void) const
Definition: mcontainer.cpp:54
virtual const string & GetSourceFileName(void) const
Definition: mcontainer.cpp:65
static const CNamespace KEmptyNamespace
Definition: namespace.hpp:104
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:264
CNcbiDiag –.
Definition: ncbidiag.hpp:924
bool IsRefToParent(void) const
Definition: reftype.hpp:77
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
bool IsNonEmpty(void) const
Definition: unitype.hpp:76
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
const_iterator find(const key_type &key) const
Definition: map.hpp:293
void erase(iterator pos)
Definition: map.hpp:307
const_iterator end() const
Definition: map.hpp:292
iterator insert(const value_type &val)
Definition: map.hpp:305
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
string MakeFileName(const string &fname, size_t addLength)
Definition: fileutil.cpp:340
string Path(const string &dir, const string &file)
Definition: fileutil.cpp:243
#define false
Definition: bool.h:36
static int type
Definition: getdata.c:31
static char tmp[3200]
Definition: utf8.c:42
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
Definition: ncbimisc.hpp:480
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
element_type * release(void)
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:472
string
Definition: cgiapp.hpp:687
#define NCBI_ERRCODE_X
Returns currently set default error code.
Definition: ncbidiag.hpp:376
#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
EDataSpec
Definition: serialdef.hpp:204
@ eNSQNotSet
Definition: serialdef.hpp:199
#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::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2821
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define kEmptyStr
Definition: ncbistr.hpp:123
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
#define NPOS
Definition: ncbistr.hpp:133
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
#define NcbiEmptyString
Definition: ncbistr.hpp:122
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
virtual const string & GetModuleName(void) const
Get module name.
Definition: typeinfo.cpp:254
void DataSpec(EDataSpec spec)
Definition: typeinfo.cpp:182
void SetModuleName(const string &name)
Set module name.
Definition: typeinfo.cpp:259
void SetFullAlias(bool set=true)
Definition: aliasinfo.hpp:76
size_t GetSize(void) const
Get size of data object in memory (like sizeof in C)
#define ErrCode()
Get the error code for the last failed system function.
Definition: mdb.c:377
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
FILE * file
int i
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Common macro to detect used sanitizers and suppress memory leaks if run under LeakSanitizer.
#define NCBI_LSAN_DISABLE_GUARD
#define GetArgs
Avoid preprocessor name clash with the NCBI C Toolkit.
Definition: ncbiapp_api.hpp:54
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static const char * prefix[]
Definition: pcregrep.c:405
@ eForbidden
User is not authorized for the retrieval.
string indent(" ")
string Identifier(const string &typeName, bool capitalize)
Definition: srcutil.cpp:40
CNcbiOstream & PrintASNNewLine(CNcbiOstream &out, int indent)
Definition: srcutil.cpp:130
Definition: inftrees.h:24
Definition: type.c:6
#define _ASSERT
int g(Seg_Gsm *spe, Seq_Mtf *psm, Thd_Gsm *tdg)
Definition: thrddgri.c:44
Modified on Sun Jun 16 04:38:04 2024 by modify_doxy.py rev. 669887