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; }
void CNamespace::CloseAllAbove(size_t level, CNcbiOstream& out) { for ( size_t size = GetNamespaceLevel(); size > level; --size ) Close(out); }