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

Go to the SVN repository for this file.

00001 #ifndef NAMESPACE__HPP
00002 #define NAMESPACE__HPP
00003 
00004 /*  $Id: namespace.hpp 55304 2012-08-07 13:34:40Z gouriano $
00005 * ===========================================================================
00006 *
00007 *                            PUBLIC DOMAIN NOTICE
00008 *               National Center for Biotechnology Information
00009 *
00010 *  This software/database is a "United States Government Work" under the
00011 *  terms of the United States Copyright Act.  It was written as part of
00012 *  the author's official duties as a United States Government employee and
00013 *  thus cannot be copyrighted.  This software/database is freely available
00014 *  to the public for use. The National Library of Medicine and the U.S.
00015 *  Government have not placed any restriction on its use or reproduction.
00016 *
00017 *  Although all reasonable efforts have been taken to ensure the accuracy
00018 *  and reliability of the software and data, the NLM and the U.S.
00019 *  Government do not and cannot warrant the performance or results that
00020 *  may be obtained by using this software or data. The NLM and the U.S.
00021 *  Government disclaim all warranties, express or implied, including
00022 *  warranties of performance, merchantability or fitness for any particular
00023 *  purpose.
00024 *
00025 *  Please cite the author in any work or product based on this material.
00026 *
00027 * ===========================================================================
00028 *
00029 * Author: Eugene Vasilchenko
00030 *
00031 * File Description:
00032 *   !!! PUT YOUR DESCRIPTION HERE !!!
00033 *
00034 */
00035 
00036 #include <corelib/ncbistd.hpp>
00037 #include <vector>
00038 
00039 BEGIN_NCBI_SCOPE
00040 
00041 class CNamespace
00042 {
00043 public:
00044     typedef vector<string> TNamespaces;
00045 
00046     CNamespace(void);
00047     CNamespace(const string& s);
00048 
00049     void Set(const CNamespace& ns, CNcbiOstream& out, bool mainHeader = true);
00050 
00051     string GetNamespaceRef(const CNamespace& ns) const;
00052     void UseFullname(bool full)
00053     {
00054         m_UseFullname = full;
00055     }
00056     bool UseFullname(void) const
00057     {
00058         return m_UseFullname;
00059     }
00060 
00061     void Reset(void)
00062         {
00063             m_Namespaces.clear();
00064             m_UseFullname = false;
00065         }
00066     void Reset(CNcbiOstream& out)
00067         {
00068             CloseAllAbove(0, out);
00069         }
00070 
00071     CNcbiOstream& PrintFullName(CNcbiOstream& out) const;
00072 
00073     operator string(void) const
00074         {
00075             string s;
00076             ToStringTo(s);
00077             return s;
00078         }
00079 
00080     string ToString(void) const
00081         {
00082             string s;
00083             ToStringTo(s);
00084             return s;
00085         }
00086 
00087     bool IsEmpty(void) const
00088         {
00089             return m_Namespaces.empty();
00090         }
00091     DECLARE_OPERATOR_BOOL(!IsEmpty());
00092 
00093     bool operator==(const CNamespace& ns) const
00094         {
00095             size_t myLevel = GetNamespaceLevel();
00096             return ns.GetNamespaceLevel() == myLevel &&
00097                 EqualLevels(ns) == myLevel;
00098         }
00099     bool operator!=(const CNamespace& ns) const
00100         {
00101             return !(*this == ns);
00102         }
00103 
00104     static const CNamespace KEmptyNamespace;
00105     static const CNamespace KNCBINamespace;
00106     static const CNamespace KSTDNamespace;
00107     static const string KNCBINamespaceName;
00108     static const string KSTDNamespaceName;
00109     static const string KNCBINamespaceDefine;
00110     static const string KSTDNamespaceDefine;
00111 
00112     bool InNCBI(void) const
00113         {
00114             return m_Namespaces.size() > 0 &&
00115                 m_Namespaces[0] == KNCBINamespaceName;
00116         }
00117     bool InSTD(void) const
00118         {
00119             return m_Namespaces.size() > 0 &&
00120                 m_Namespaces[0] == KSTDNamespaceName;
00121         }
00122     bool IsNCBI(void) const
00123         {
00124             return m_Namespaces.size() == 1 &&
00125                 m_Namespaces[0] == KNCBINamespaceName;
00126         }
00127     bool IsSTD(void) const
00128         {
00129             return m_Namespaces.size() == 1 &&
00130                 m_Namespaces[0] == KSTDNamespaceName;
00131         }
00132 
00133 protected:
00134     const TNamespaces& GetNamespaces(void) const
00135         {
00136             return m_Namespaces;
00137         }
00138     size_t GetNamespaceLevel(void) const
00139         {
00140             return m_Namespaces.size();
00141         }
00142 
00143     void Open(const string& s, CNcbiOstream& out, bool mainHeader = true);
00144     void Close(CNcbiOstream& out);
00145     void CloseAllAbove(size_t level, CNcbiOstream& out);
00146 
00147     size_t EqualLevels(const CNamespace& ns) const;
00148 
00149     void ToStringTo(string& s) const;
00150 
00151     TNamespaces m_Namespaces;
00152     bool m_UseFullname;
00153 };
00154 
00155 inline
00156 CNcbiOstream& operator<<(CNcbiOstream& out, const CNamespace& ns)
00157 {
00158     return ns.PrintFullName(out);
00159 }
00160 
00161 END_NCBI_SCOPE
00162 
00163 #endif  /* NAMESPACE__HPP */
Modified on Fri May 22 11:59:19 2015 by modify_doxy.py rev. 426318