📄 classstr.cpp
字号:
if ( generateDoNotDeleteThisObject ) { code.ClassPublic() << " virtual void DoNotDeleteThisObject(void);\n" "\n"; methods << "void "<<methodPrefix<<"DoNotDeleteThisObject(void)\n" "{\n" " "<<code.GetParentClassName()<<"::DoNotDeleteThisObject();\n"; ITERATE ( TMembers, i, m_Members ) { if ( !i->ref && i->type->GetKind() == eKindObject ) { methods << " "<<i->mName<<".DoNotDeleteThisObject();\n"; } } methods << "}\n" "\n"; } // generate destruction code { for ( TMembers::const_reverse_iterator i = m_Members.rbegin(); i != m_Members.rend(); ++i ) { code.AddDestructionCode(i->type->GetDestructionCode(i->valueName)); } } // generate type info methods << "BEGIN_NAMED_"; if ( haveUserClass ) methods << "BASE_"; if ( wrapperClass ) methods << "IMPLICIT_"; methods << "CLASS_INFO(\""<<GetExternalName()<<"\", "<<classPrefix<<GetClassNameDT()<<")\n" "{\n"; if ( !GetModuleName().empty() ) { methods << " SET_CLASS_MODULE(\""<<GetModuleName()<<"\");\n"; } if ( !m_ParentClassName.empty() ) { code.SetParentClass(m_ParentClassName, m_ParentClassNamespace); methods << " SET_PARENT_CLASS("<<m_ParentClassNamespace.GetNamespaceRef(code.GetNamespace())<<m_ParentClassName<<");\n"; } { // All or none of the members must be tagged bool useTags = false; bool hasUntagged = false; // All tags must be different map<int, bool> tag_map; size_t member_index = 0; ITERATE ( TMembers, i, m_Members ) { ++member_index; if ( i->memberTag >= 0 ) { if ( hasUntagged ) { NCBI_THROW(CDatatoolException,eInvalidData, "No explicit tag for some members in " + GetModuleName()); } if ( tag_map[i->memberTag] ) NCBI_THROW(CDatatoolException,eInvalidData, "Duplicate tag: " + i->cName + " [" + NStr::IntToString(i->memberTag) + "] in " + GetModuleName()); tag_map[i->memberTag] = true; useTags = true; } else { hasUntagged = true; if ( useTags ) { NCBI_THROW(CDatatoolException,eInvalidData, "No explicit tag for " + i->cName + " in " + GetModuleName()); } } methods << " ADD_NAMED_"; bool isNull = x_IsNullType(i); if (isNull) { methods << "NULL_"; } bool addNamespace = false; bool addCType = false; bool addEnum = false; bool addRef = false; bool ref = i->ref; if ( ref ) { methods << "REF_"; addCType = true; } else { switch ( i->type->GetKind() ) { case eKindStd: case eKindString: if ( i->type->HaveSpecialRef() ) { addRef = true; } else { methods << "STD_"; } break; case eKindEnum: methods << "ENUM_"; addEnum = true; if ( !i->type->GetNamespace().IsEmpty() && code.GetNamespace() != i->type->GetNamespace()) { _TRACE("EnumNamespace: "<<i->type->GetNamespace()<<" from "<<code.GetNamespace()); methods << "IN_"; addNamespace = true; } break; default: addRef = true; break; } } methods << "MEMBER(\""<<i->externalName<<"\""; if (!isNull) { methods << ", "<<i->mName; } if ( addNamespace ) methods << ", "<<i->type->GetNamespace(); if ( addCType ) methods << ", "<<i->type->GetCType(code.GetNamespace()); if ( addEnum ) methods << ", "<<i->type->GetEnumName(); if ( addRef ) methods << ", "<<i->type->GetRef(code.GetNamespace()); methods << ")"; if ( !i->defaultValue.empty() ) { methods << "->SetDefault("; if ( ref ) methods << "new NCBI_NS_NCBI::CRef< "+i->tName+" >("; methods << "new "<<i->tName<<"("<<i->defaultValue<<')'; if ( ref ) methods << ')'; methods << ')'; if ( i->haveFlag ) methods << "->SetSetFlag(MEMBER_PTR("SET_PREFIX"[0]))"; } else if ( i->optional ) { methods << "->SetOptional()"; if (i->haveFlag) { methods << "->SetSetFlag(MEMBER_PTR("SET_PREFIX"[0]))"; } } else if (i->haveFlag) { methods << "->SetSetFlag(MEMBER_PTR("SET_PREFIX"[0]))"; } if ( i->delayed ) { methods << "->SetDelayBuffer(MEMBER_PTR("DELAY_PREFIX<< i->cName<<"))"; } if (i->nonEmpty) { methods << "->SetNonEmpty()"; } if (i->noPrefix) { methods << "->SetNoPrefix()"; } if (i->attlist) { methods << "->SetAttlist()"; } if (i->noTag) { methods << "->SetNotag()"; } if ( i->memberTag >= 0 ) { methods << "->GetId().SetTag(" << i->memberTag << ")"; } methods << ";\n"; } if ( isAttlist || useTags ) { // Tagged class is not sequential methods << " info->SetRandomOrder(true);\n"; } else { // Just query the flag to avoid warnings. methods << " info->RandomOrder();\n"; } } methods << "}\n" "END_CLASS_INFO\n" "\n";}void CClassTypeStrings::GenerateUserHPPCode(CNcbiOstream& out) const{ if (CClassCode::GetDoxygenComments()) { out << "\n" << "/** @addtogroup "; if (!CClassCode::GetDoxygenGroup().empty()) { out << CClassCode::GetDoxygenGroup(); } else { out << "dataspec_" << GetModuleName(); } out << "\n *\n" << " * @{\n" << " */\n\n"; } bool wrapperClass = (m_Members.size() == 1) && m_Members.front().cName.empty(); bool generateCopy = wrapperClass && m_Members.front().type->CanBeCopied(); out << "/////////////////////////////////////////////////////////////////////////////\n"; if (CClassCode::GetDoxygenComments()) { out << "///\n" "/// " << GetClassNameDT() << " --\n" "///\n\n"; } out << "class "; if ( !CClassCode::GetExportSpecifier().empty() ) out << CClassCode::GetExportSpecifier() << " "; out << GetClassNameDT()<<" : public "<<GetClassNameDT()<<"_Base\n" "{\n" " typedef "<<GetClassNameDT()<<"_Base Tparent;\n" "public:\n"; DeclareConstructor(out, GetClassNameDT()); ITERATE ( TMembers, i, m_Members ) { if (i->simple && !x_IsNullType(i)) { out << " " << GetClassNameDT() <<"(const "<< i->type->GetCType(GetNamespace()) << "& value);" << "\n"; break; } } DeclareDestructor(out, GetClassNameDT(), false); if ( generateCopy ) { const SMemberInfo& info = m_Members.front(); string cType = info.type->GetCType(GetNamespace()); out << " /// Copy constructor\n" " "<<GetClassNameDT()<<"(const "<<cType<<"& value);\n\n" "\n" " /// Assignment operator\n" " "<<GetClassNameDT()<<"& operator=(const "<<cType<<"& value);\n\n" "\n"; } ITERATE ( TMembers, i, m_Members ) { if (i->simple && !x_IsNullType(i)) { out << " /// Conversion operator to \'" << i->type->GetCType(GetNamespace()) << "\' type.\n" " operator const " << i->type->GetCType(GetNamespace()) << "&(void) const;\n\n"; out << " /// Assignment operator.\n" " " << GetClassNameDT() << "& operator="<<"(const "<< i->type->GetCType(GetNamespace()) << "& value);\n" << "\n"; break; } } out << "private:\n" << " // Prohibit copy constructor and assignment operator\n" " "<<GetClassNameDT()<<"(const "<<GetClassNameDT()<<"& value);\n" " "<<GetClassNameDT()<<"& operator=(const "<<GetClassNameDT()<< "& value);\n" "\n"; out << "};\n"; if (CClassCode::GetDoxygenComments()) { out << "/* @} */\n"; } out << "\n"; out << "/////////////////// "<<GetClassNameDT()<<" inline methods\n" "\n" "// constructor\n" "inline\n"<< GetClassNameDT()<<"::"<<GetClassNameDT()<<"(void)\n" "{\n" "}\n" "\n"; ITERATE ( TMembers, i, m_Members ) { if (i->simple && !x_IsNullType(i)) { out << "inline\n" << GetClassNameDT()<<"::"<<GetClassNameDT()<<"(const "<< i->type->GetCType(GetNamespace()) << "& value)\n"<< "{\n" " Set" << i->cName << "(value);\n" << "}\n" "\n"; } } if ( generateCopy ) { const SMemberInfo& info = m_Members.front(); out << "// data copy constructors\n" "inline\n"<< GetClassNameDT()<<"::"<<GetClassNameDT()<<"(const "<<info.tName<<"& value)\n" " : Tparent(value)\n" "{\n" "}\n" "\n" "// data assignment operators\n" "inline\n"<< GetClassNameDT()<<"& "<<GetClassNameDT()<<"::operator=(const "<<info.tName<<"& value)\n" "{\n" " Set(value);\n" " return *this;\n" "}\n" "\n"; } ITERATE ( TMembers, i, m_Members ) { if (i->simple && !x_IsNullType(i)) { out << "inline\n"<< GetClassNameDT() << "::" "operator const " << i->type->GetCType(GetNamespace()) << "&(void) const\n" << "{\n" << " return Get" << i->cName << "();\n" << "}\n" << "\n"; out << "inline\n"<< GetClassNameDT() << "& " << GetClassNameDT() << "::" "operator="<<"(const "<< i->type->GetCType(GetNamespace()) << "& value)\n" << "{\n" << " Set" << i->cName << "(value);\n" << " return *this;\n" << "}\n" "\n"; break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -