lib45d
45Drives C++ Library Development Documentation
ConfigNode.hpp
1 // -*- C++ -*-
2 /*
3  * Copyright (C) 2021 Joshua Boudreau <jboudreau@45drives.com>
4  *
5  * This file is part of lib45d.
6  *
7  * lib45d is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * lib45d is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with lib45d. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <string>
24 #include <unordered_map>
25 
26 namespace ffd {
31  class ConfigNode {
32  public:
33  std::string value_;
34  std::unordered_map<std::string, ConfigNode>
36 
43  ConfigNode(std::string value, std::unordered_map<std::string, ConfigNode> *sub_map)
44  : value_(value)
45  , sub_map_(sub_map)
46  , is_copy_(false) {}
51  ConfigNode(void) : value_(""), sub_map_(nullptr), is_copy_(false) {}
59  ConfigNode(const ConfigNode &other)
60  : value_(other.value_)
61  , sub_map_(other.sub_map_)
62  , is_copy_(true) {}
71  : value_(std::move(other.value_))
72  , sub_map_(std::move(other.sub_map_))
73  , is_copy_(false) {
74  other.sub_map_ = nullptr;
75  }
85  value_ = std::move(other.value_);
86  sub_map_ = std::move(other.sub_map_);
87  is_copy_ = false;
88  other.sub_map_ = nullptr;
89  return *this;
90  }
97  if (sub_map_ && !is_copy_)
98  delete sub_map_;
99  }
100  private:
101  bool is_copy_;
102  };
103 } // namespace ffd
ffd::ConfigNode::operator=
ConfigNode & operator=(ConfigNode &&other)
Assignment move constructor.
Definition: ConfigNode.hpp:84
ffd::ConfigNode::sub_map_
std::unordered_map< std::string, ConfigNode > * sub_map_
Pointer to submap for config sections.
Definition: ConfigNode.hpp:35
ffd::ConfigNode::ConfigNode
ConfigNode(ConfigNode &&other)
Move constructor.
Definition: ConfigNode.hpp:70
ffd::ConfigNode::~ConfigNode
~ConfigNode()
Destroy the ConfigNode object.
Definition: ConfigNode.hpp:96
ffd::ConfigNode::ConfigNode
ConfigNode(const ConfigNode &other)
Copy construct a new ConfigNode object.
Definition: ConfigNode.hpp:59
ffd
45Drives namespace
Definition: Bytes.hpp:27
ffd::ConfigNode::is_copy_
bool is_copy_
Set in copy constructor to avoid double deletion of *sub_map_.
Definition: ConfigNode.hpp:101
ffd::ConfigNode::ConfigNode
ConfigNode(void)
Construct a new empty ConfigNode object.
Definition: ConfigNode.hpp:51
ffd::ConfigNode::ConfigNode
ConfigNode(std::string value, std::unordered_map< std::string, ConfigNode > *sub_map)
Construct a new ConfigNode object.
Definition: ConfigNode.hpp:43
ffd::ConfigNode::value_
std::string value_
string from config file after '='
Definition: ConfigNode.hpp:33
ffd::ConfigNode
Class for config_map_ entries.
Definition: ConfigNode.hpp:31