Skip to content

Commit

Permalink
Split tag.hpp into three files
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Nov 5, 2018
1 parent df4413a commit a32e279
Show file tree
Hide file tree
Showing 10 changed files with 510 additions and 367 deletions.
20 changes: 18 additions & 2 deletions projectfiles/VC14/wesnoth.vcxproj
Expand Up @@ -2809,7 +2809,21 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)SDL\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\seed_rng.cpp" />
<ClCompile Include="..\..\src\serialization\tag.cpp">
<ClCompile Include="..\..\src\serialization\schema\key.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Serialization\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\serialization\schema\tag.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Serialization\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\serialization\schema\type.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Serialization\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)Serialization\</ObjectFileName>
Expand Down Expand Up @@ -4033,7 +4047,9 @@
<ClInclude Include="..\..\src\theme.hpp" />
<ClInclude Include="..\..\src\time_of_day.hpp" />
<ClInclude Include="..\..\src\tod_manager.hpp" />
<ClInclude Include="..\..\src\serialization\tag.hpp" />
<ClInclude Include="..\..\src\serialization\schema\key.hpp" />
<ClInclude Include="..\..\src\serialization\schema\tag.hpp" />
<ClInclude Include="..\..\src\serialization\schema\type.hpp" />
<ClInclude Include="..\..\src\tooltips.hpp" />
<ClInclude Include="..\..\src\units\abilities.hpp" />
<ClInclude Include="..\..\src\units\animation.hpp" />
Expand Down
16 changes: 14 additions & 2 deletions projectfiles/VC14/wesnoth.vcxproj.filters
Expand Up @@ -1010,7 +1010,13 @@
<ClCompile Include="..\..\src\utils\name_generator_factory.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="..\..\src\serialization\tag.cpp">
<ClCompile Include="..\..\src\serialization\schema\key.cpp">
<Filter>serialization</Filter>
</ClCompile>
<ClCompile Include="..\..\src\serialization\schema\tag.cpp">
<Filter>serialization</Filter>
</ClCompile>
<ClCompile Include="..\..\src\serialization\schema\type.cpp">
<Filter>serialization</Filter>
</ClCompile>
<ClCompile Include="..\..\src\tests\main.cpp">
Expand Down Expand Up @@ -2513,7 +2519,13 @@
<ClInclude Include="..\..\src\utils\scope_exit.hpp">
<Filter>utils</Filter>
</ClInclude>
<ClInclude Include="..\..\src\serialization\tag.hpp">
<ClInclude Include="..\..\src\serialization\schema\key.hpp">
<Filter>serialization</Filter>
</ClInclude>
<ClInclude Include="..\..\src\serialization\schema\tag.hpp">
<Filter>serialization</Filter>
</ClInclude>
<ClInclude Include="..\..\src\serialization\schema\type.hpp">
<Filter>serialization</Filter>
</ClInclude>
<ClInclude Include="..\..\src\actions\advancement.hpp">
Expand Down
4 changes: 3 additions & 1 deletion source_lists/libwesnoth_core
Expand Up @@ -21,7 +21,9 @@ serialization/parser.cpp
serialization/preprocessor.cpp
serialization/schema_validator.cpp
serialization/string_utils.cpp
serialization/tag.cpp
serialization/schema/key.cpp
serialization/schema/tag.cpp
serialization/schema/type.cpp
serialization/tokenizer.cpp
serialization/unicode.cpp
serialization/validator.cpp
Expand Down
63 changes: 63 additions & 0 deletions src/serialization/schema/key.cpp
@@ -0,0 +1,63 @@
/*
Copyright (C) 2011 - 2018 by Sytyi Nick <nsytyi@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

/**
* @file
* Implementation of key.hpp.
*/

#include "serialization/schema/key.hpp"

#include "config.hpp"

namespace schema_validation
{

class_key::class_key(const config& cfg)
: name_(cfg["name"].str())
, type_(cfg["type"].str())
, default_()
, mandatory_(false)
, fuzzy_(name_.find_first_of("*?") != std::string::npos)
{
if(cfg.has_attribute("mandatory")) {
mandatory_ = cfg["mandatory"].to_bool();
} else {
if(cfg.has_attribute("default")) {
default_ = cfg["default"].str();
}
}
}

void class_key::print(std::ostream& os, int level) const
{
std::string s;
for(int j = 0; j < level; j++) {
s.append(" ");
}

os << s << "[key]\n" << s << " name=\"" << name_ << "\"\n" << s << " type=\"" << type_ << "\"\n";

if(is_mandatory()) {
os << s << " mandatory=\"true\"\n";
} else {
os << s << " default=" << default_ << "\n";
}

// TODO: Other attributes

os << s << "[/key]\n";
}

} // namespace schema_validation
143 changes: 143 additions & 0 deletions src/serialization/schema/key.hpp
@@ -0,0 +1,143 @@
/*
Copyright (C) 2011 - 2018 by Sytyi Nick <nsytyi@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

/**
* @file
* This file contains object "key", which is used to store
* information about keys while annotation parsing.
*/

#pragma once

#include <iosfwd>
#include <string>

class config;

namespace schema_validation
{

/**
* class_key is used to save the information about one key.
* Key has next info: name, type, default value or key is mandatory.
*/
class class_key
{
public:
class_key()
: name_("")
, type_("")
, default_("\"\"")
, mandatory_(false)
, fuzzy_(false)
{
}

class_key(const std::string& name, const std::string& type, const std::string& def = "\"\"")
: name_(name)
, type_(type)
, default_(def)
, mandatory_(def.empty())
, fuzzy_(name.find_first_of("*?") != std::string::npos)
{
}

class_key(const config&);

const std::string& get_name() const
{
return name_;
}

const std::string& get_type() const
{
return type_;
}

const std::string& get_default() const
{
return default_;
}

bool is_mandatory() const
{
return mandatory_;
}

bool is_fuzzy() const {
return fuzzy_;
}

void set_name(const std::string& name)
{
name_ = name;
}

void set_type(const std::string& type)
{
type_ = type;
}

void set_default(const std::string& def)
{
default_ = def;
if(def.empty()) {
mandatory_ = true;
}
}

void set_mandatory(bool mandatory)
{
mandatory_ = mandatory;
}

void set_fuzzy(bool f)
{
fuzzy_ = f;
}

/** is used to print key info
* the format is next
* [key]
* name="name"
* type="type"
* default="default"
* mandatory="true/false"
* [/key]
*/
void print(std::ostream& os, int level) const;

/** Compares keys by name. Used in std::sort, i.e. */
bool operator<(const class_key& k) const
{
return (get_name() < k.get_name());
}

private:
/** Name of key. */
std::string name_;

/** Type of key. */
std::string type_;

/** Default value. */
std::string default_;

/** Shows, if key is a mandatory key. */
bool mandatory_;

/** Whether the key is a fuzzy match. */
bool fuzzy_;
};
}

0 comments on commit a32e279

Please sign in to comment.