The Battle for Wesnoth  1.19.0-dev
key.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2024
3  by Sytyi Nick <nsytyi@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 /**
17  * @file
18  * Implementation of key.hpp.
19  */
20 
22 
23 #include "config.hpp"
24 
26 {
27 
29  : name_(cfg["name"].str())
30  , type_(cfg["type"].str())
31  , default_()
32  , mandatory_(false)
33  , fuzzy_(name_.find_first_of("*?") != std::string::npos)
34 {
35  if(cfg.has_attribute("mandatory")) {
36  mandatory_ = cfg["mandatory"].to_bool();
37  } else {
38  if(cfg.has_attribute("default")) {
39  default_ = cfg["default"].str();
40  }
41  }
42 }
43 
44 void wml_key::print(std::ostream& os, int level) const
45 {
46  std::string s;
47  for(int j = 0; j < level; j++) {
48  s.append(" ");
49  }
50 
51  os << s << "[key]\n" << s << " name=\"" << name_ << "\"\n" << s << " type=\"" << type_ << "\"\n";
52 
53  if(is_mandatory()) {
54  os << s << " mandatory=\"true\"\n";
55  } else {
56  os << s << " default=" << default_ << "\n";
57  }
58 
59  // TODO: Other attributes
60 
61  os << s << "[/key]\n";
62 }
63 
64 } // namespace schema_validation
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
bool has_attribute(config_key_type key) const
Definition: config.cpp:156
bool mandatory_
Shows, if key is a mandatory key.
Definition: key.hpp:139
std::string type_
Type of key.
Definition: key.hpp:133
std::string default_
Default value.
Definition: key.hpp:136
bool is_mandatory() const
Definition: key.hpp:74
std::string name_
Name of key.
Definition: key.hpp:130
void print(std::ostream &os, int level) const
is used to print key info the format is next [key] name="name" type="type" default="default" mandator...
Definition: key.cpp:44
This file contains object "key", which is used to store information about keys while annotation parsi...
static map_location::DIRECTION s