NCBI C++ ToolKit
namespace.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef NAMESPACE__HPP
2 #define NAMESPACE__HPP
3 
4 /* $Id: namespace.hpp 55304 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 
40 
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;
52  void UseFullname(bool full)
53  {
54  m_UseFullname = full;
55  }
56  bool UseFullname(void) const
57  {
58  return m_UseFullname;
59  }
60 
61  void Reset(void)
62  {
63  m_Namespaces.clear();
64  m_UseFullname = false;
65  }
67  {
68  CloseAllAbove(0, out);
69  }
70 
72 
73  operator string(void) const
74  {
75  string s;
76  ToStringTo(s);
77  return s;
78  }
79 
80  string ToString(void) const
81  {
82  string s;
83  ToStringTo(s);
84  return s;
85  }
86 
87  bool IsEmpty(void) const
88  {
89  return m_Namespaces.empty();
90  }
92 
93  bool operator==(const CNamespace& ns) const
94  {
95  size_t myLevel = GetNamespaceLevel();
96  return ns.GetNamespaceLevel() == myLevel &&
97  EqualLevels(ns) == myLevel;
98  }
99  bool operator!=(const CNamespace& ns) const
100  {
101  return !(*this == ns);
102  }
103 
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 
112  bool InNCBI(void) const
113  {
114  return m_Namespaces.size() > 0 &&
116  }
117  bool InSTD(void) const
118  {
119  return m_Namespaces.size() > 0 &&
121  }
122  bool IsNCBI(void) const
123  {
124  return m_Namespaces.size() == 1 &&
126  }
127  bool IsSTD(void) const
128  {
129  return m_Namespaces.size() == 1 &&
131  }
132 
133 protected:
134  const TNamespaces& GetNamespaces(void) const
135  {
136  return m_Namespaces;
137  }
138  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;
153 };
154 
155 inline
157 {
158  return ns.PrintFullName(out);
159 }
160 
162 
163 #endif /* NAMESPACE__HPP */
static const CNamespace KEmptyNamespace
Definition: namespace.hpp:104
bool m_UseFullname
Definition: namespace.hpp:152
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: namespace.cpp:183
void ToStringTo(string &s) const
Definition: namespace.cpp:190
std::ofstream out("events_result.xml")
main entry point for tests
vector< string > TNamespaces
Definition: namespace.hpp:44
TNamespaces m_Namespaces
Definition: namespace.hpp:151
bool UseFullname(void) const
Definition: namespace.hpp:56
DECLARE_OPERATOR_BOOL(!IsEmpty())
void UseFullname(bool full)
Definition: namespace.hpp:52
void Reset(void)
Definition: namespace.hpp:61
string
Definition: cgiapp.hpp:512
void Close(CNcbiOstream &out)
Definition: namespace.cpp:161
static const string KSTDNamespaceDefine
Definition: namespace.hpp:110
bool InNCBI(void) const
Definition: namespace.hpp:112
size_t GetNamespaceLevel(void) const
Definition: namespace.hpp:138
bool operator!=(const CNamespace &ns) const
Definition: namespace.hpp:99
CNamespace(void)
Definition: namespace.cpp:49
string ToString(void) const
Definition: namespace.hpp:80
void Reset(CNcbiOstream &out)
Definition: namespace.hpp:66
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
static const CNamespace KNCBINamespace
Definition: namespace.hpp:105
bool IsSTD(void) const
Definition: namespace.hpp:127
static const CNamespace KSTDNamespace
Definition: namespace.hpp:106
static const string KNCBINamespaceName
Definition: namespace.hpp:107
string GetNamespaceRef(const CNamespace &ns) const
Definition: namespace.cpp:97
bool operator==(const CNamespace &ns) const
Definition: namespace.hpp:93
bool IsNCBI(void) const
Definition: namespace.hpp:122
static const string KSTDNamespaceName
Definition: namespace.hpp:108
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:142
const TNamespaces & GetNamespaces(void) const
Definition: namespace.hpp:134
void Open(const string &s, CNcbiOstream &out, bool mainHeader=true)
Definition: namespace.cpp:139
bool IsEmpty(void) const
Definition: namespace.hpp:87
void CloseAllAbove(size_t level, CNcbiOstream &out)
Definition: namespace.cpp:177
CNcbiOstream & operator<<(CNcbiOstream &out, const CNamespace &ns)
Definition: namespace.hpp:156
size_t EqualLevels(const CNamespace &ns) const
Definition: namespace.cpp:79
void Set(const CNamespace &ns, CNcbiOstream &out, bool mainHeader=true)
Definition: namespace.cpp:89
bool InSTD(void) const
Definition: namespace.hpp:117
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
static const string KNCBINamespaceDefine
Definition: namespace.hpp:109
Modified on Thu Feb 22 13:23:06 2018 by modify_doxy.py rev. 546573