27#ifndef VARCONF_VARIABLE_H
28#define VARCONF_VARIABLE_H
30#include "varconf_defs.h"
32#include <sigc++/trackable.h>
40typedef enum { GLOBAL = 0x1u << 0u,
45class VARCONF_API
VarBase :
virtual public sigc::trackable {
57 VARCONF_API
friend std::ostream& operator<<(std::ostream& out,
const VarBase& v);
58 VARCONF_API
friend bool operator ==(
const VarBase& one,
const VarBase& two);
59 VARCONF_API
friend bool operator !=(
const VarBase& one,
const VarBase& two);
62 virtual VarBase& operator=(
bool b);
63 virtual VarBase& operator=(
int i);
64 virtual VarBase& operator=(
double d);
65 virtual VarBase& operator=(
const std::string& s);
66 virtual VarBase& operator=(
const char* s);
68 virtual explicit operator bool()
const;
69 virtual explicit operator int()
const;
70 virtual explicit operator double()
const;
71 virtual explicit operator std::string()
const;
73 virtual bool is_bool();
74 virtual bool is_int();
75 virtual bool is_double();
76 virtual bool is_string();
78 Scope scope()
const {
return m_scope; }
80 void setScope(Scope s) { m_scope = s; }
82 mutable bool m_have_bool;
83 mutable bool m_have_int;
84 mutable bool m_have_double;
87 mutable bool m_val_bool;
88 mutable int m_val_int;
89 mutable double m_val_double;
96VARCONF_API std::ostream& operator<<(std::ostream& out,
const VarBase& v);
97VARCONF_API
bool operator ==(
const VarBase& one,
const VarBase& two);
108 void ref() {++m_ref;}
109 void unref() {
if(--m_ref == 0)
delete this;}
111 VarBase *elem() {
return m_var;}
125 VarPtr(
const VarPtr &vp) : m_box(vp.m_box) {m_box->ref();}
130 if(vp.m_box != m_box) {
139 VarBase& elem()
const {
return *m_box->elem();}
140 VarBase* operator->()
const {
return m_box->elem();}
147typedef std::vector<Variable> VarList;
164 friend std::ostream& operator<<(std::ostream& out,
const Variable& v)
165 {
return (out << v.elem());}
167 {
return (one.elem() == two.elem());}
169 {
return (one.elem() != two.elem());}
176 Variable& operator=(
const std::string& s);
178 Variable& operator=(
const VarList& v);
180 explicit operator bool()
const {
return bool(this->elem());}
181 explicit operator int()
const {
return int(this->elem());}
182 explicit operator double()
const {
return double(this->elem());}
183 explicit operator std::string()
const {
return std::string(this->elem());}
184 VarList* array()
const {
return dynamic_cast<VarList*
>(&this->elem());}
187 std::string as_string()
const {
return std::string(this->elem());}
195 bool is_bool()
const {
return (*this)->is_bool();}
196 bool is_int()
const {
return (*this)->is_int();}
197 bool is_double()
const {
return (*this)->is_double();}
198 bool is_string()
const {
return (*this)->is_string();}
199 bool is_array()
const {
return array() !=
nullptr;}
211 friend std::ostream& operator<<(std::ostream& out,
const VarArray& v);
212 friend bool operator ==(
const VarBase& one,
const VarArray& two) {
return false;}
213 friend bool operator ==(
const VarArray& one,
const VarBase& two) {
return false;}
216 explicit operator bool()
const override;
217 explicit operator int()
const override;
218 explicit operator double()
const override;
219 explicit operator std::string()
const override;
221 bool is_bool()
override;
222 bool is_int()
override;
223 bool is_double()
override;
224 bool is_string()
override;