Graphite  Version 3
An experimental 3D geometry processing program
text_utils.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 
38 #ifndef H_OGF_BASIC_OS_TEXT_UTILS_H
39 #define H_OGF_BASIC_OS_TEXT_UTILS_H
40 
42 
43 #include <string>
44 #include <vector>
45 #include <map>
46 #include <iostream>
47 
53 namespace OGF {
54 
55  namespace TextUtils {
56 
61  class BASIC_API Environment {
62  public:
69  bool has_variable(const std::string& name) const ;
70 
77  std::string value(const std::string& name) const ;
78 
88  const std::vector<std::string>& values(const std::string& name) const ;
89 
99  void set_value(const std::string& name, const std::string& value) ;
100 
110  void set_values(const std::string& name, const std::vector<std::string>& values) ;
111 
120  void append_value(const std::string& name, const std::string& value) ;
121 
130  void append_values(const std::string& name, const std::vector<std::string>& values) ;
131 
138  void clear_value(const std::string& name) ;
139 
143  void clear() ;
144 
150  void print(std::ostream& out) const ;
151 
152  private:
153  typedef std::map< std::string, std::vector<std::string> > EnvMap ;
154  EnvMap data_ ;
155  } ;
156 
157 
165  inline std::ostream& operator<<(std::ostream& out, const Environment& env) {
166  env.print(out) ;
167  return out ;
168  }
169 
175  void BASIC_API read_environment_file(
176  const std::string& file_name,
177  Environment& environment
178  ) ;
179 
190  void BASIC_API find_and_replace(
191  std::istream& in, std::ostream& out,
192  const Environment& env
193  ) ;
194 
201  void BASIC_API concatenate(
202  std::istream& in, std::ostream& out
203  ) ;
204 
214  bool BASIC_API file_contains_string(
215  const std::string& file_name, const std::string& x
216  ) ;
217  }
218 }
219 
220 #endif
Manages a set of name-value or name-values pairs, used to manipulate text files.
Definition: text_utils.h:61
void append_value(const std::string &name, const std::string &value)
Appends a value to the set of values associated with a variable.
std::string value(const std::string &name) const
Gets the value of a variable.
void clear_value(const std::string &name)
Clears the values of a variable.
void print(std::ostream &out) const
Outputs the contents of this Enviroment to a stream.
void set_values(const std::string &name, const std::vector< std::string > &values)
Sets the values of a variable.
void append_values(const std::string &name, const std::vector< std::string > &values)
Appends a set of values to the set of values associated with a variable.
void set_value(const std::string &name, const std::string &value)
Sets the value of a variable.
const std::vector< std::string > & values(const std::string &name) const
Gets the vector of values associated with a variable.
bool has_variable(const std::string &name) const
Tests whether a variable exists in this Environment.
void clear()
Removes all the variables and their values.
Global Graphite namespace.
Definition: common.h:76
std::ostream & operator<<(std::ostream &out, const ArgList &args)
Prints an ArgList into a stream.
Definition: arg_list.h:527
Definitions common to all include files in the basic library.
void concatenate(std::istream &in, std::ostream &out)
Copies the content of an input stream to an output stream.
bool file_contains_string(const std::string &file_name, const std::string &x)
Tests whether a file contains an occurence of a string.
void find_and_replace(std::istream &in, std::ostream &out, const Environment &env)
Performs variables substitution in a stream.
void read_environment_file(const std::string &file_name, Environment &environment)
Reads an Environment from a file.