📄 main.cxx
字号:
strm << tag << GetClass() << ' '; Module->SetIndentLevel(1);}void TypeBase::PrintFinish(std::ostream & strm) const{ Module->SetIndentLevel(-1); strm << ' ' << constraints; if (isOptional) strm << " OPTIONAL"; if (defaultValue.get() != NULL) strm << " DEFAULT " << *defaultValue; strm << '\n';}void TypeBase::SetName(const std::string& newName){ name = newName; identifier = MakeIdentifierC(name);}void TypeBase::SetDefaultValue(ValuePtr value) { defaultValue = value; }void TypeBase::AdjustIdentifier(bool){ identifier = Module->GetPrefix() + MakeIdentifierC(name);}void TypeBase::SetTag(Tag::Type type, unsigned num, Tag::Mode mode){ tag.type = type; tag.number = num; tag.mode = mode;}void TypeBase::SetParameters(ParameterList& list){ parameters.swap(list);}void TypeBase::MoveConstraints(TypeBase& from){ constraints.insert(constraints.end(), from.constraints.begin(), from.constraints.end()); from.constraints.resize(0);}void TypeBase::CopyConstraints(const TypeBase& from){ for (size_t i = 0; i < from.constraints.size(); ++i) { std::auto_ptr<Constraint> cons = from.constraints[i]->Clone(); constraints.push_back(ConstraintPtr(cons)); }}void TypeBase::FlattenUsedTypes(){}TypePtr TypeBase::FlattenThisType(TypePtr& self, const TypeBase &){ return self;}bool TypeBase::IsChoice() const{ return false;}bool TypeBase::IsParameterizedType() const{ return false;}bool TypeBase::IsPrimitiveType() const{ return true;}void TypeBase::GenerateCplusplus(std::ostream & hdr, std::ostream & cxx, std::ostream & inl){ Indent indent(hdr.precision()); if (IsPrimitiveType() && !NeedGenInfo() ) { hdr << indent << "typedef "<< GetTypeName() << ' ' << GetIdentifier() << ";\n\n"; } else { BeginGenerateCplusplus(hdr, cxx, inl); hdr << indent+4 << GetIdentifier() << "(const " << GetIdentifier() << "& other) : Inherited(other) {}\n"; EndGenerateCplusplus(hdr, cxx, inl); }}void TypeBase::GenerateForwardDecls(std::ostream &){}void TypeBase::GenerateOperators(std::ostream &, std::ostream &, const TypeBase &){}std::string TypeBase::GetTypeName() const{ return GetAncestorClass();}bool TypeBase::CanReferenceType() const{ return false;}bool TypeBase::ReferencesType(const TypeBase &) const{ return false;}bool TypeBase::IsParameterisedImport() const{ return false;}void TypeBase::BeginGenerateCplusplus(std::ostream & hdr, std::ostream & cxx, std::ostream & inl){ shortClassNameString = GetIdentifier(); parameters.GenerateCplusplus(templatePrefix, shortClassNameString); if (outerClassName.size()) classNameString = outerClassName + "::" + shortClassNameString; else classNameString = shortClassNameString; // Output header file declaration of class Indent indent(hdr.precision()) ; if (hdr.precision() == 0) { hdr << "//\n" "// " << GetClassNameString() << "\n" "//\n" "\n"; } cxx << "//\n" "// " << GetClassNameString() << "\n" "//\n" "\n"; GenerateForwardDecls(hdr); if (outerClassName.size() == 0) hdr << templatePrefix; hdr << indent << "class " ; hdr << GetIdentifier() << " : public " << GetTypeName() << "\n" << indent << "{" << '\n' << indent << " typedef " << GetTypeName() << " Inherited;\n"; hdr << indent << " protected:\n" << indent << " " << GetIdentifier() << "(const void* info) : Inherited(info) {}\n" << indent << " public:\n"; GenerateConstructors(hdr, cxx, inl);}void TypeBase::EndGenerateCplusplus(std::ostream & hdr, std::ostream & cxx, std::ostream & inl){ GenerateOperators(hdr, cxx, *this); Indent indent(hdr.precision()); // Output header file declaration of class hdr << indent << " " << shortClassNameString << " * clone() const" << ";\n"; inl << GetTemplatePrefix() << "inline " << GetClassNameString() << "* " << GetClassNameString() << "::clone() const\n" << "{ return static_cast<"<< shortClassNameString << "*> (Inherited::clone()); }" << "\n\n"; cxx << "\n"; hdr << indent << " static bool equal_type(const ASN1::AbstractData&);\n"; inl << GetTemplatePrefix() << "inline bool " << GetClassNameString() << "::equal_type(const ASN1::AbstractData& type)\n" << "{ return type.info() == reinterpret_cast<const ASN1::AbstractData::InfoType*>(&theInfo); }" << "\n\n"; GenerateInfo(this, hdr, cxx); hdr << indent << "};\n\n"; isGenerated = true;}void TypeBase::GenerateInfo(const TypeBase* type, std::ostream & hdr, std::ostream& cxx){ Indent indent(hdr.precision()+4) ; hdr << indent << dllMacroExport << "static const InfoType theInfo;\n"; cxx << GetTemplatePrefix() << "const "<< type->GetClassNameString() << "::InfoType " << type->GetClassNameString() << "::theInfo = {\n" << " " << GetAncestorClass() << "::create,\n" << " "; type->GenerateTags(cxx); cxx << "\n" << "};\n\n";}void TypeBase::GenerateTags(std::ostream & cxx) const{ cxx << "0x" << std::hex << std::setw(6) << std::setfill('0') << (tag.type << 22 | tag.number) << std::dec << std::setw(0) << std::setfill(' ');}void TypeBase::GenerateCplusplusConstraints(const std::string & prefix, std::ostream & hdr, std::ostream & cxx, std::ostream & inl) const{ for (size_t i = 0; i < constraints.size(); i++) constraints[i]->GenerateCplusplus( " "+ prefix + "setConstraints(", hdr, cxx, inl);}void TypeBase::BeginParseValue() const{ BeginParseThisTypeValue();}void TypeBase::EndParseValue() const{ BraceTokenContext = InObjectSetContext ? OBJECT_BRACE : '{'; EndParseThisTypeValue(); ValueTypeContext.reset();}void TypeBase::BeginParseValueSet() const{ BraceTokenContext = VALUESET_BRACE; BeginParseValue();}void TypeBase::EndParseValueSet() const{ EndParseValue();}bool TypeBase::FwdDeclareMe(std::ostream & hdr){ if (CanBeFwdDeclared(true)) { hdr << Indent(hdr.precision()) << "class " << GetTypeName()<< ";\n"; return true; } return false;}std::string TypeBase::GetPrimitiveType() const{ return GetIdentifier() + "::const_reference";}bool TypeBase::CanBeFwdDeclared(bool ) const { return false; }bool TypeBase::HasConstraints() const { return constraints.size() > 0;}void TypeBase::RemovePERInvisibleConstraint(const ParameterPtr& vp){ constraints.erase( std::remove_if(constraints.begin(), constraints.end(), boost::bind(&Constraint::HasPERInvisibleConstraint, _1, boost::ref(*vp))), constraints.end());}void TypeBase::RemovePERInvisibleConstraints(){ std::for_each(parameters.rep.begin(), parameters.rep.end(), boost::bind(&TypeBase::RemovePERInvisibleConstraint, this, _1));}const std::string& TypeBase::GetCModuleName() const { return module->GetCModuleName(); }void TypeBase::GenerateConstructors(std::ostream & hdr, std::ostream & , std::ostream & ){ Indent indent(hdr.precision()) ; hdr << indent +4 << GetIdentifier() << "() : Inherited(&theInfo) {}\n" ;}TypePtr TypeBase::SeqOfFlattenThisType(const TypeBase & parent, TypePtr result){ if (!IsPrimitiveType() || NeedGenInfo() || HasNonStandardTag()) result.reset(new DefinedType(result, parent)); return result;;}bool TypeBase::NeedGenInfo() const { if (HasNonStandardTag() && isupper(name[0])) return true; return false;}const char* TypeBase::GetClass() const{ return typeid(*this).name();}/////////////////////////////////////////////////////////DefinedType::DefinedType(const std::string& name) : TypeBase(Tag::IllegalUniversalTag, Module), referenceName(name){ unresolved = true;}DefinedType::DefinedType(TypePtr refType): TypeBase(*refType){ CopyConstraints(*refType); baseType = refType; unresolved = false;}DefinedType::DefinedType(TypePtr refType, TypePtr& bType) : TypeBase(*refType), referenceName(bType->GetName()){ MoveConstraints(*refType); baseType = bType; unresolved = false;}DefinedType::DefinedType(TypePtr refType, const std::string & refName) : TypeBase(*refType){ MoveConstraints(*refType); ConstructFromType(refType, refName);}DefinedType::DefinedType(TypePtr refType, const TypeBase & parent) : TypeBase(*refType){ if (name.size()) ConstructFromType(refType, parent.GetName() + '_' + name); else ConstructFromType(refType, parent.GetName() + "_subtype");}void DefinedType::ConstructFromType(TypePtr& refType, const std::string & name){ referenceName = name; refType->SetName(name); if (name != "" || !refType->IsPrimitiveType() || refType->HasConstraints()){ Module->AddType(refType); } baseType = refType; unresolved = false;}void DefinedType::PrintOn(std::ostream & strm) const{ PrintStart(strm); strm << referenceName << ' '; PrintFinish(strm);}bool DefinedType::CanReferenceType() const{ return true;}bool DefinedType::IsChoice() const{ if (baseType.get()) return baseType->IsChoice(); return false;}bool DefinedType::IsParameterizedType() const{ if (baseType.get()) return baseType->IsParameterizedType(); return false;} bool DefinedType::ReferencesType(const TypeBase & type) const{ ResolveReference(); return type.GetName() == referenceName;}bool DefinedType::UseType(const TypeBase & type) const{ return type.GetName() == referenceName;}void DefinedType::GenerateOperators(std::ostream & hdr, std::ostream & cxx, const TypeBase & actualType){ if (baseType.get()) { std::string basicTypeName = baseType->GetPrimitiveType(); if (basicTypeName.find("::const_reference") == -1) { if (basicTypeName.find("::value_type::") != -1) basicTypeName = basicTypeName.substr(basicTypeName.find_last_of(':')+1); Indent indent(hdr.precision() + 4); hdr << indent << GetIdentifier() << "(" << basicTypeName << " value)" << ":Inherited(value){}\n"; } baseType->GenerateOperators(hdr, cxx, actualType); } else std::cout << "Cannot find type " << referenceName << " to generate operators\n";}const char * DefinedType::GetAncestorClass() const{ if (baseType.get()) return baseType->GetAncestorClass(); return NULL;}std::string DefinedType::GetTypeName() const{ ResolveReference(); if (baseType.get() == NULL) return MakeIdentifierC(referenceName); std::string result = baseType->GetIdentifier(); if (baseType->GetIdentifier().size() == 0 || result == GetIdentifier()) return baseType->GetTypeName(); if (GetCModuleName() != Module->GetCModuleName()) result = GetCModuleName() + "::" + result; return result;}void DefinedType::BeginParseThisTypeValue() const{ if (baseType.get()) baseType->BeginParseThisTypeValue(); else {// used when this type is an INTEGER and the subsequent value is a NamedNumber. IdentifierTokenContext = VALUEREFERENCE; }}void DefinedType::EndParseThisTypeValue() const{ if (baseType.get()) baseType->EndParseThisTypeValue(); else IdentifierTokenContext = IDENTIFIER;}void DefinedType::ResolveReference() const{ if (unresolved) { unresolved = false; if (Module == 0) Module = module; baseType = Module->FindType(referenceName); if (baseType.get() != NULL) { if (!HasNonStandardTag()) ((Tag&)defaultTag) = ((Tag&)tag) = baseType->GetTag(); } }}void DefinedType::GenerateCplusplus(std::ostream & hdr, std::ostream & cxx, std::ostream & inl){ if (constraints.empty() && !HasNonStandardTag()) { hdr << Indent(hdr.precision()) << "typedef " << GetTypeName() << ' ' << GetIdentifier() << ";\n"; } else { TypeBase::GenerateCplusplus(hdr, cxx, inl); }}bool DefinedType::CanBeFwdDeclared(bool isComponent) const { ResolveReference(); if (isComponent && baseType.get()) return baseType->CanBeFwdDeclared(); else if (constraints.empty() && !HasNonStandardTag()) return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -