The Battle for Wesnoth  1.15.12+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 #pragma once
17 
18 #include "deprecation.hpp"
19 #include "exceptions.hpp"
20 #include "filesystem.hpp"
21 #include "game_version.hpp"
22 #include <optional>
23 
24 #include <iosfwd>
25 #include <map>
26 #include <vector>
27 
28 class config_writer;
29 class config;
30 
31 typedef std::map<std::string, struct preproc_define> preproc_map;
32 
34 {
36  : value()
37  , arguments()
39  , textdomain()
40  , linenum(0)
41  , location()
42  {
43  }
44 
45  explicit preproc_define(const std::string& val)
46  : value(val)
47  , arguments()
49  , textdomain()
50  , linenum(0)
51  , location()
52  {
53  }
54 
55  preproc_define(const std::string& val,
56  const std::vector<std::string>& args,
57  const std::map<std::string, std::string>& optargs,
58  const std::string& domain,
59  int line,
60  const std::string& loc,
61  const std::string& dep_msg,
62  std::optional<DEP_LEVEL> dep_lvl, const version_info& dep_ver)
63  : value(val)
64  , arguments(args)
65  , optional_arguments(optargs)
66  , textdomain(domain)
67  , linenum(line)
68  , location(loc)
69  , deprecation_message(dep_msg)
70  , deprecation_level(dep_lvl)
71  , deprecation_version(dep_ver)
72  {
73  }
74 
75  std::string value;
76 
77  std::vector<std::string> arguments;
78 
79  std::map<std::string, std::string> optional_arguments;
80 
81  std::string textdomain;
82 
83  int linenum;
84 
85  std::string location;
86 
87  std::string deprecation_message;
88 
89  std::optional<DEP_LEVEL> deprecation_level;
90 
92 
93  bool is_deprecated() const {
94  return deprecation_level.has_value();
95  }
96 
97  void write(config_writer&, const std::string&) const;
98  void write_argument(config_writer&, const std::string&) const;
99 
100  void read(const config&);
101  void read_argument(const config&);
102 
103  static preproc_map::value_type read_pair(const config&);
104 
105  bool operator==(const preproc_define&) const;
106 
107  bool operator<(const preproc_define&) const;
108 
109  bool operator!=(const preproc_define& v) const
110  {
111  return !operator==(v);
112  }
113 };
114 
115 std::ostream& operator<<(std::ostream& stream, const preproc_define& def);
116 
118 {
119  struct error : public game::error
120  {
121  error(const std::string& message)
122  : game::error(message)
123  {
124  }
125  };
126 };
127 
128 std::string lineno_string(const std::string& lineno);
129 
130 std::ostream& operator<<(std::ostream& stream, const preproc_map::value_type& def);
131 
132 /**
133  * Function to use the WML preprocessor on a file.
134  *
135  * @param defines A map of symbols defined.
136  * @param fname The file to be preprocessed.
137  *
138  * @returns The resulting preprocessed file data.
139  */
140 filesystem::scoped_istream preprocess_file(const std::string& fname, preproc_map* defines = nullptr);
141 
142 void preprocess_resource(const std::string& res_name,
143  preproc_map* defines_map,
144  bool write_cfg = false,
145  bool write_plain_cfg = false,
146  const std::string& target_directory = "");
std::vector< std::string > arguments
std::optional< DEP_LEVEL > deprecation_level
void write(config_writer &, const std::string &) 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, std::optional< DEP_LEVEL > dep_lvl, const version_info &dep_ver)
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:37
std::string deprecation_message
std::string value
std::string lineno_string(const std::string &lineno)
bool operator==(const preproc_define &) const
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:27
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:59
static preproc_map::value_type read_pair(const config &)
bool operator<(const preproc_define &) const
std::map< std::string, std::string > optional_arguments