varconf  1.0.3
Configuration library for the Worldforge system.
dyntypes.cpp
1 /*
2  * dyntypes.cpp - implementation of the dynamically derived value container types.
3  * Copyright (C) 2001, Ron Steinke
4  * (C) 2003-2006 Alistair Riddoch
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * Contact: Joseph Zupko
21  * jaz147@psu.edu
22  *
23  * 189 Reese St.
24  * Old Forge, PA 18518
25  */
26 
27 #include "dyntypes.h"
28 #include "config.h"
29 
30 #include <string>
31 
32 namespace varconf {
33 namespace dynvar {
34 
35 Concat::~Concat() = default;
36 
37 Concat& Concat::operator=(const Concat& c)
38 {
39  VarBase::operator=(c);
40  m_v1 = c.m_v1;
41  m_v2 = c.m_v2;
42  return *this;
43 }
44 
45 void Concat::set_val()
46 {
47  if(m_v1.is_string() && m_v2.is_string())
48  VarBase::operator=(std::string(m_v1) + std::string(m_v2));
49  else
50  VarBase::operator=(VarBase()); // Set it invalid
51 }
52 
53 Ternary::~Ternary() = default;
54 
55 Ternary& Ternary::operator=(const Ternary& t)
56 {
57  VarBase::operator=(t);
58  m_test = t.m_test;
59  m_true = t.m_true;
60  m_false = t.m_false;
61  return *this;
62 }
63 
64 void Ternary::set_val()
65 {
66  if(!m_test.is_bool())
67  VarBase::operator=(VarBase()); // Set it invalid
68  else {
69  Variable val = bool(m_test) ? m_true : m_false;
70  val.is_string(); // Force a call of set_val()
71  VarBase::operator=(val.elem());
72  }
73 }
74 
75 Item::~Item() = default;
76 
77 Item& Item::operator=(const Item& i)
78 {
79  VarBase::operator=(i);
80  m_section = i.m_section;
81  m_key = i.m_key;
82  return *this;
83 }
84 
85 void Item::assign(const Variable & v, Scope scope)
86 {
87  Config::inst()->setItem(m_section, m_key, v, scope);
88 }
89 
90 void Item::set_val()
91 {
92  if(Config::inst()->findItem(m_section, m_key))
93  VarBase::operator=(Config::inst()->getItem(m_section, m_key).elem());
94  else
95  VarBase::operator=(VarBase()); // Set it invalid
96 }
97 
98 }} // namespace varconf::dynvar