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

Go to the SVN repository for this file.

1 #ifndef PROJECT_TREE_BUILDER__FILE_CONTENTS__HPP
2 #define PROJECT_TREE_BUILDER__FILE_CONTENTS__HPP
3 
4 /* $Id: file_contents.hpp 61719 2014-02-10 19:58:23Z 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: Viatcheslav Gorelenkov
30  *
31  */
32 
33 #include "stl_msvc_usage.hpp"
34 
35 #include <string>
36 #include <list>
37 
38 #include <corelib/ncbistre.hpp>
39 #include "proj_utils.hpp"
40 
41 #include <corelib/ncbienv.hpp>
43 
50 };
51 
53 
54 /// Key Value struct
55 struct SKeyValue
56 {
57  SKeyValue(void) {
58  m_Append = false;
59  }
60  string m_Key;
61  string m_Value;
62  bool m_Append;
63 };
64 
65 /////////////////////////////////////////////////////////////////////////////
66 ///
67 /// CSimpleMakeFileContents --
68 ///
69 /// Abstraction of makefile contents.
70 ///
71 /// Container for key/values pairs with included makefiles parsing support.
72 
74 {
75 public:
78 
80  const CSimpleMakeFileContents& contents);
81 
82  CSimpleMakeFileContents(const string& file_path, EMakeFileType type);
83  CSimpleMakeFileContents(const string& file_path);
84 
86 
87  /// Key-Value(s) pairs
90 
91  bool IsEmpty(void) const {
92  return m_Contents.empty();
93  }
94 
95  static void LoadFrom(const string& file_path, CSimpleMakeFileContents* fc);
96  void AddDefinition( const string& key, const string& value);
97  void RemoveDefinition( const string& key);
98  bool HasDefinition( const string& key) const;
99  bool DoesValueContain(const string& key, const string& value, bool ifnokey=true) const;
100  bool GetPathValue(const string& key, string& value) const;
101  bool GetValue(const string& key, string& value) const;
102  bool GetValue(const string& key, list<string>& value) const;
103 
109  };
110  bool CollectValues( const string& key, list<string>& values, EHowToCollect how) const;
111 
113  {
114  return m_Type;
115  }
116  const string& GetFileName(void) const
117  {
118  return m_Filename;
119  }
120 
121  void Save(const string& filename) const;
122  /// Debug dump
123  void Dump(CNcbiOstream& ostr, const list<string>* skip=0) const;
124 
125  void SetParent( const CSimpleMakeFileContents* parent)
126  {
127  m_Parent = parent;
128  }
129 
130  void Clear(void);
131  void SetValueSeparator(const string& sep)
132  {
133  m_ValueSeparator = sep;
134  }
135 
136 private:
137 
138  void SetFrom(const CSimpleMakeFileContents& contents);
139 
140  struct SParser;
141  friend struct SParser;
142 
143  struct SParser
144  {
146 
147  void StartParse(void);
148  void AcceptLine(const string& line);
149  void EndParse(void);
150  void LoadInclude(const string& file_path);
151 
154 
156 
157  private:
158  SParser(void);
159  SParser(const SParser&);
161  };
162 
163  void AddReadyKV(const SKeyValue& kv);
165  string m_Filename;
168  bool m_Raw;
169 };
170 
171 
173 
174 #endif //PROJECT_TREE_BUILDER__FILE_CONTENTS__HPP
CSimpleMakeFileContents –.
static void LoadFrom(const string &file_path, CSimpleMakeFileContents *fc)
void RemoveDefinition(const string &key)
bool HasDefinition(const string &key) const
void Dump(CNcbiOstream &ostr, const list< string > *skip=0) const
Debug dump.
bool GetPathValue(const string &key, string &value) const
void SetFrom(const CSimpleMakeFileContents &contents)
CSimpleMakeFileContents & operator=(const CSimpleMakeFileContents &contents)
EMakeFileType GetMakeType(void) const
const string & GetFileName(void) const
bool IsEmpty(void) const
bool CollectValues(const string &key, list< string > &values, EHowToCollect how) const
bool DoesValueContain(const string &key, const string &value, bool ifnokey=true) const
void AddDefinition(const string &key, const string &value)
const CSimpleMakeFileContents * m_Parent
bool GetValue(const string &key, string &value) const
map< string, list< string > > TContents
Key-Value(s) pairs.
void AddReadyKV(const SKeyValue &kv)
void SetValueSeparator(const string &sep)
void Save(const string &filename) const
void SetParent(const CSimpleMakeFileContents *parent)
bool empty() const
Definition: map.hpp:149
Definition: map.hpp:338
string MakeFileTypeAsString(EMakeFileType type)
EMakeFileType
@ eMakeType_Undefined
@ eMakeType_Potential
@ eMakeType_Expendable
@ eMakeType_Excluded
@ eMakeType_ExcludedByReq
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Defines unified interface to application:
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
#define fc
SParser & operator=(const SParser &)
CSimpleMakeFileContents * m_FileContents
void AcceptLine(const string &line)
void LoadInclude(const string &file_path)
Key Value struct.
string m_Key
string m_Value
SKeyValue(void)
Definition: type.c:6
Modified on Fri May 24 14:50:12 2024 by modify_doxy.py rev. 669887