The Battle for Wesnoth  1.15.1+dev
key.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2018 by Sytyi Nick <nsytyi@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
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  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Implementation of key.hpp.
18  */
19 
21 
22 #include "config.hpp"
23 
25 {
26 
28  : name_(cfg["name"].str())
29  , type_(cfg["type"].str())
30  , default_()
31  , mandatory_(false)
32  , fuzzy_(name_.find_first_of("*?") != std::string::npos)
33 {
34  if(cfg.has_attribute("mandatory")) {
35  mandatory_ = cfg["mandatory"].to_bool();
36  } else {
37  if(cfg.has_attribute("default")) {
38  default_ = cfg["default"].str();
39  }
40  }
41 }
42 
43 void wml_key::print(std::ostream& os, int level) const
44 {
45  std::string s;
46  for(int j = 0; j < level; j++) {
47  s.append(" ");
48  }
49 
50  os << s << "[key]\n" << s << " name=\"" << name_ << "\"\n" << s << " type=\"" << type_ << "\"\n";
51 
52  if(is_mandatory()) {
53  os << s << " mandatory=\"true\"\n";
54  } else {
55  os << s << " default=" << default_ << "\n";
56  }
57 
58  // TODO: Other attributes
59 
60  os << s << "[/key]\n";
61 }
62 
63 } // namespace schema_validation
bool has_attribute(config_key_type key) const
Definition: config.cpp:213
bool is_mandatory() const
Definition: key.hpp:73
STL namespace.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string default_
Default value.
Definition: key.hpp:135
bool mandatory_
Shows, if key is a mandatory key.
Definition: key.hpp:138
std::string name_
Name of key.
Definition: key.hpp:129
std::string type_
Type of key.
Definition: key.hpp:132
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:43
static map_location::DIRECTION s
This file contains object "key", which is used to store information about keys while annotation parsi...
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92