1 /*  $Id: ptb_registry.hpp 425324 2014-01-28 13:52:04Z gouriano $
2  * ===========================================================================
3  *
4  *                            PUBLIC DOMAIN NOTICE
5  *               National Center for Biotechnology Information
6  *
7  *  This software/database is a "United States Government Work" under the
8  *  terms of the United States Copyright Act.  It was written as part of
9  *  the author's official duties as a United States Government employee and
10  *  thus cannot be copyrighted.  This software/database is freely available
11  *  to the public for use. The National Library of Medicine and the U.S.
12  *  Government have not placed any restriction on its use or reproduction.
13  *
14  *  Although all reasonable efforts have been taken to ensure the accuracy
15  *  and reliability of the software and data, the NLM and the U.S.
16  *  Government do not and cannot warrant the performance or results that
17  *  may be obtained by using this software or data. The NLM and the U.S.
18  *  Government disclaim all warranties, express or implied, including
19  *  warranties of performance, merchantability or fitness for any particular
20  *  purpose.
21  *
22  *  Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Andrei Gourianov
27  *
28  */
29 
30 #ifndef __PTB_REGISTRY__
31 #define __PTB_REGISTRY__
32 
33 #include <corelib/ncbireg.hpp>
34 #include <map>
35 
36 BEGIN_NCBI_SCOPE
37 
38 
39 class CPtbRegistry
40 {
41 public:
42     CPtbRegistry(void);
43     CPtbRegistry(const IRWRegistry& reg);
44     ~CPtbRegistry(void);
45 
46     string GetString(const string& section,
47                      const string& name,
48                      const string& default_value = kEmptyStr) const;
49 
Get(const string & section,const string & name) const50     string Get(const string& section,
51                const string& name) const
52     {
53         return m_IsEmpty ? kEmptyStr : GetString(section,name);
54     }
HasEntry(const string & section,const string & name=kEmptyStr) const55     bool HasEntry(const string& section, const string& name = kEmptyStr) const
56     {
57         return m_IsEmpty ? false : m_Registry->HasEntry(section, name, IRegistry::fCountCleared);
58     }
Read(CNcbiIstream & is)59     void Read(CNcbiIstream& is)
60     {
61         m_Registry->Read(is);
62         m_IsEmpty = m_Registry->Empty();
63     }
Empty(void) const64     bool Empty(void) const
65     {
66         return m_IsEmpty;
67     }
EnumerateSections(list<string> * sections) const68     void EnumerateSections(list<string>* sections) const
69     {
70         if (!m_IsEmpty) {m_Registry->EnumerateSections(sections);}
71     }
72 
EnumerateEntries(const string & section,list<string> * entries) const73     void EnumerateEntries(const string& section,
74                           list<string>* entries) const
75     {
76         if (!m_IsEmpty) {m_Registry->EnumerateEntries(section,entries);}
77     }
78 
79 private:
80     mutable map<string,string> m_Cache;
81     AutoPtr<IRWRegistry> m_Registry;
82     bool m_IsEmpty;
83 
84     /// forbidden
85     CPtbRegistry(const CPtbRegistry&);
86     CPtbRegistry& operator=(const CPtbRegistry&);
87 };
88 
89 END_NCBI_SCOPE
90 
91 #endif // __PTB_REGISTRY__
92