void CNamespace::Set(const CNamespace& ns, CNcbiOstream& out, bool mainHeader) { size_t equal = EqualLevels(ns); CloseAllAbove(equal, out); for ( size_t i = equal, end = ns.GetNamespaceLevel(); i < end; ++i ) Open(ns.GetNamespaces()[i], out, mainHeader); }
size_t CNamespace::EqualLevels(const CNamespace& ns) const { size_t end = min(GetNamespaceLevel(), ns.GetNamespaceLevel()); for ( size_t i = 0; i < end; ++i ) { if ( GetNamespaces()[i] != ns.GetNamespaces()[i] ) return i; } return end; }
string CNamespace::GetNamespaceRef(const CNamespace& ns) const { size_t equal = EqualLevels(ns); string s; if ( equal == GetNamespaceLevel() ) { // internal namespace } else { // reference from root equal = 0; if ( ns.InNCBI() ) { s = KNCBINamespaceDefine; equal = 1; } else if ( ns.InSTD() ) { s = KSTDNamespaceDefine; equal = 1; } if ( equal == 1 ) { // std or ncbi if ( InNCBI() ) s.erase(); else s += "::"; } else { // from root s = "::"; } } for ( size_t i = equal, end = ns.GetNamespaceLevel(); i < end; ++i ) { s += ns.GetNamespaces()[i]; s += "::"; } return s; }
bool operator==(const CNamespace& ns) const { size_t myLevel = GetNamespaceLevel(); return ns.GetNamespaceLevel() == myLevel && EqualLevels(ns) == myLevel; }