1 #ifndef NAMESPACE__HPP
2 #define NAMESPACE__HPP
3
4 /* $Id: namespace.hpp 371238 2012-08-07 13:34:40Z gouriano $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Eugene Vasilchenko
30 *
31 * File Description:
32 * !!! PUT YOUR DESCRIPTION HERE !!!
33 *
34 */
35
36 #include <corelib/ncbistd.hpp>
37 #include <vector>
38
39 BEGIN_NCBI_SCOPE
40
41 class CNamespace
42 {
43 public:
44 typedef vector<string> TNamespaces;
45
46 CNamespace(void);
47 CNamespace(const string& s);
48
49 void Set(const CNamespace& ns, CNcbiOstream& out, bool mainHeader = true);
50
51 string GetNamespaceRef(const CNamespace& ns) const;
UseFullname(bool full)52 void UseFullname(bool full)
53 {
54 m_UseFullname = full;
55 }
UseFullname(void) const56 bool UseFullname(void) const
57 {
58 return m_UseFullname;
59 }
60
Reset(void)61 void Reset(void)
62 {
63 m_Namespaces.clear();
64 m_UseFullname = false;
65 }
Reset(CNcbiOstream & out)66 void Reset(CNcbiOstream& out)
67 {
68 CloseAllAbove(0, out);
69 }
70
71 CNcbiOstream& PrintFullName(CNcbiOstream& out) const;
72
operator string(void) const73 operator string(void) const
74 {
75 string s;
76 ToStringTo(s);
77 return s;
78 }
79
ToString(void) const80 string ToString(void) const
81 {
82 string s;
83 ToStringTo(s);
84 return s;
85 }
86
IsEmpty(void) const87 bool IsEmpty(void) const
88 {
89 return m_Namespaces.empty();
90 }
91 DECLARE_OPERATOR_BOOL(!IsEmpty());
92
operator ==(const CNamespace & ns) const93 bool operator==(const CNamespace& ns) const
94 {
95 size_t myLevel = GetNamespaceLevel();
96 return ns.GetNamespaceLevel() == myLevel &&
97 EqualLevels(ns) == myLevel;
98 }
operator !=(const CNamespace & ns) const99 bool operator!=(const CNamespace& ns) const
100 {
101 return !(*this == ns);
102 }
103
104 static const CNamespace KEmptyNamespace;
105 static const CNamespace KNCBINamespace;
106 static const CNamespace KSTDNamespace;
107 static const string KNCBINamespaceName;
108 static const string KSTDNamespaceName;
109 static const string KNCBINamespaceDefine;
110 static const string KSTDNamespaceDefine;
111
InNCBI(void) const112 bool InNCBI(void) const
113 {
114 return m_Namespaces.size() > 0 &&
115 m_Namespaces[0] == KNCBINamespaceName;
116 }
InSTD(void) const117 bool InSTD(void) const
118 {
119 return m_Namespaces.size() > 0 &&
120 m_Namespaces[0] == KSTDNamespaceName;
121 }
IsNCBI(void) const122 bool IsNCBI(void) const
123 {
124 return m_Namespaces.size() == 1 &&
125 m_Namespaces[0] == KNCBINamespaceName;
126 }
IsSTD(void) const127 bool IsSTD(void) const
128 {
129 return m_Namespaces.size() == 1 &&
130 m_Namespaces[0] == KSTDNamespaceName;
131 }
132
133 protected:
GetNamespaces(void) const134 const TNamespaces& GetNamespaces(void) const
135 {
136 return m_Namespaces;
137 }
GetNamespaceLevel(void) const138 size_t GetNamespaceLevel(void) const
139 {
140 return m_Namespaces.size();
141 }
142
143 void Open(const string& s, CNcbiOstream& out, bool mainHeader = true);
144 void Close(CNcbiOstream& out);
145 void CloseAllAbove(size_t level, CNcbiOstream& out);
146
147 size_t EqualLevels(const CNamespace& ns) const;
148
149 void ToStringTo(string& s) const;
150
151 TNamespaces m_Namespaces;
152 bool m_UseFullname;
153 };
154
155 inline
operator <<(CNcbiOstream & out,const CNamespace & ns)156 CNcbiOstream& operator<<(CNcbiOstream& out, const CNamespace& ns)
157 {
158 return ns.PrintFullName(out);
159 }
160
161 END_NCBI_SCOPE
162
163 #endif /* NAMESPACE__HPP */
164