The Battle for Wesnoth  1.15.2+dev
preprocessor.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <dave@whitevine.net>
3  Copyright (C) 2005 - 2018 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
4  Part of the Battle for Wesnoth Project https://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 #pragma once
19 
20 #include "filesystem.hpp"
21 #include <iosfwd>
22 #include <map>
23 #include <vector>
24 #include <boost/optional.hpp>
25 
26 #include "exceptions.hpp"
27 #include "game_version.hpp"
28 #include "deprecation.hpp"
29 
30 class config_writer;
31 class config;
32 
33 typedef std::map<std::string, struct preproc_define> preproc_map;
34 
36 {
38  : value()
39  , arguments()
41  , textdomain()
42  , linenum(0)
43  , location()
44  {
45  }
46 
47  explicit preproc_define(const std::string& val)
48  : value(val)
49  , arguments()
51  , textdomain()
52  , linenum(0)
53  , location()
54  {
55  }
56 
57  preproc_define(const std::string& val,
58  const std::vector<std::string>& args,
59  const std::map<std::string, std::string>& optargs,
60  const std::string& domain,
61  int line,
62  const std::string& loc,
63  const std::string& dep_msg,
64  boost::optional<DEP_LEVEL> dep_lvl, const version_info& dep_ver)
65  : value(val)
66  , arguments(args)
67  , optional_arguments(optargs)
68  , textdomain(domain)
69  , linenum(line)
70  , location(loc)
71  , deprecation_message(dep_msg)
72  , deprecation_level(dep_lvl)
73  , deprecation_version(dep_ver)
74  {
75  }
76 
77  std::string value;
78 
79  std::vector<std::string> arguments;
80 
81  std::map<std::string, std::string> optional_arguments;
82 
83  std::string textdomain;
84 
85  int linenum;
86 
87  std::string location;
88 
89  std::string deprecation_message;
90 
91  boost::optional<DEP_LEVEL> deprecation_level = boost::none;
92 
94 
95  bool is_deprecated() const {
96  return deprecation_level != boost::none;
97  }
98 
99  void write(config_writer&, const std::string&) const;
100  void write_argument(config_writer&, const std::string&) const;
101 
102  void read(const config&);
103  void read_argument(const config&);
104 
105  static preproc_map::value_type read_pair(const config&);
106 
107  bool operator==(const preproc_define&) const;
108 
109  bool operator<(const preproc_define&) const;
110 
111  bool operator!=(const preproc_define& v) const
112  {
113  return !operator==(v);
114  }
115 };
116 
117 std::ostream& operator<<(std::ostream& stream, const preproc_define& def);
118 
120 {
121  struct error : public game::error
122  {
123  error(const std::string& message)
124  : game::error(message)
125  {
126  }
127  };
128 };
129 
130 std::string lineno_string(const std::string& lineno);
131 
132 std::ostream& operator<<(std::ostream& stream, const preproc_map::value_type& def);
133 
134 /**
135  * Function to use the WML preprocessor on a file.
136  *
137  * @param defines A map of symbols defined.
138  *
139  * @returns The resulting preprocessed file data.
140  */
141 filesystem::scoped_istream preprocess_file(const std::string& fname, preproc_map* defines = nullptr);
142 
143 void preprocess_resource(const std::string& res_name,
144  preproc_map* defines_map,
145  bool write_cfg = false,
146  bool write_plain_cfg = false,
147  const std::string& target_directory = "");
std::vector< std::string > arguments
void write(config_writer &, const std::string &) const
void read(const config &)
Interfaces for manipulating version numbers of engine, add-ons, etc.
void preprocess_resource(const std::string &res_name, preproc_map *defines_map, bool write_cfg=false, bool write_plain_cfg=false, const std::string &target_directory="")
void read_argument(const config &)
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines=nullptr)
Function to use the WML preprocessor on a file.
std::string location
void write_argument(config_writer &, const std::string &) const
Class for writing a config out to a file in pieces.
version_info deprecation_version
bool is_deprecated() const
std::unique_ptr< std::istream > scoped_istream
Definition: filesystem.hpp:39
std::string deprecation_message
std::string value
std::string lineno_string(const std::string &lineno)
bool operator==(const preproc_define &) const
preproc_define(const std::string &val, const std::vector< std::string > &args, const std::map< std::string, std::string > &optargs, const std::string &domain, int line, const std::string &loc, const std::string &dep_msg, boost::optional< DEP_LEVEL > dep_lvl, const version_info &dep_ver)
boost::optional< DEP_LEVEL > deprecation_level
std::ostream & operator<<(std::ostream &stream, const preproc_define &def)
Declarations for File-IO.
Represents version numbers.
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
preproc_define(const std::string &val)
std::string textdomain
bool operator!=(const preproc_define &v) const
error(const std::string &message)
std::map< std::string, struct preproc_define > preproc_map
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
static preproc_map::value_type read_pair(const config &)
bool operator<(const preproc_define &) const
std::map< std::string, std::string > optional_arguments