The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
preprocessor.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <[email protected]>
3  Copyright (C) 2005 - 2016 by Guillaume Melquiond <[email protected]>
4  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /** @file */
17 
18 #ifndef SERIALIZATION_PREPROCESSOR_HPP_INCLUDED
19 #define SERIALIZATION_PREPROCESSOR_HPP_INCLUDED
20 
21 #include <iosfwd>
22 #include <map>
23 #include <vector>
24 
25 #include "game_errors.hpp"
26 
27 class config_writer;
28 class config;
29 
31 typedef std::map< std::string, preproc_define > preproc_map;
32 
34 {
36  explicit preproc_define(std::string const &val) : value(val), arguments(), textdomain(), linenum(0), location() {}
37  preproc_define(std::string const &val, std::vector< std::string > const &args,
38  std::string const &domain, int line, std::string const &loc)
39  : value(val), arguments(args), textdomain(domain), linenum(line), location(loc) {}
41  std::vector< std::string > arguments;
43  int linenum;
45  void write(config_writer&, const std::string&) const;
46  void write_argument(config_writer&, const std::string&) const;
47  void read(const config&);
48  void read_argument(const config &);
49  static preproc_map::value_type read_pair(const config &);
50  bool operator==(preproc_define const &) const;
51  bool operator<(preproc_define const &) const;
52  bool operator!=(preproc_define const &v) const { return !operator==(v); }
53 };
54 
55 std::ostream& operator<<(std::ostream& stream, const preproc_define& def);
56 
58  struct error : public game::error {
59  error(const std::string& message) : game::error(message) {}
60  };
61 };
62 
64 
65 std::ostream& operator<<(std::ostream& stream, const preproc_map::value_type& def);
66 
67 /**
68  * Function to use the WML preprocessor on a file.
69  *
70  * @param defines A map of symbols defined.
71  *
72  * @returns The resulting preprocessed file data.
73  */
74 std::istream *preprocess_file(std::string const &fname, preproc_map *defines = nullptr);
75 
76 void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
77  bool write_cfg=false, bool write_plain_cfg=false, std::string target_directory="");
78 
79 #endif
bool operator==(preproc_define const &) const
void read(const config &)
void write_argument(config_writer &, const std::string &) const
GLuint const GLfloat * val
Definition: glew.h:2614
bool operator<(preproc_define const &) const
void read_argument(const config &)
std::string location
std::map< std::string, preproc_define > preproc_map
GLuint GLuint stream
Definition: glew.h:5239
void preprocess_resource(const std::string &res_name, preproc_map *defines_map, bool write_cfg=false, bool write_plain_cfg=false, std::string target_directory="")
Class for writing a config out to a file in pieces.
const GLdouble * v
Definition: glew.h:1359
GLsizei const GLfloat * value
Definition: glew.h:1817
std::istream * preprocess_file(std::string const &fname, preproc_map *defines=nullptr)
Function to use the WML preprocessor on a file.
std::string value
std::string lineno_string(const std::string &lineno)
Encapsulates the map of the game.
Definition: location.hpp:38
std::vector< std::string > arguments
void write(config_writer &, const std::string &) const
std::ostream & operator<<(std::ostream &stream, const preproc_define &def)
bool operator!=(preproc_define const &v) const
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:27
std::string textdomain
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
error(const std::string &message)
preproc_define(std::string const &val, std::vector< std::string > const &args, std::string const &domain, int line, std::string const &loc)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
static preproc_map::value_type read_pair(const config &)
preproc_define(std::string const &val)
GLsizei const GLcharARB ** string
Definition: glew.h:4503