OpenStructure
Loading...
Searching...
No Matches
info_item.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of the OpenStructure project <www.openstructure.org>
3//
4// Copyright (C) 2008-2020 by the OpenStructure authors
5// Copyright (C) 2003-2010 by the IPLT authors
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License as published by the Free
9// Software Foundation; either version 3.0 of the License, or (at your option)
10// any later version.
11// This library is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14// details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this library; if not, write to the Free Software Foundation, Inc.,
18// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//------------------------------------------------------------------------------
20
21
22/*
23 high level info item interface
24
25 Author: Ansgar Philippsen
26*/
27
28#ifndef OST_DATA_INFO_ITEM_H
29#define OST_DATA_INFO_ITEM_H
30
31#include <boost/lexical_cast.hpp>
32
33#include <ost/geom/geom.hh>
34#include <ost/base.hh>
35
36#include "info_fw.hh"
37#include "info_handle.hh"
38#include "info_group.hh"
39#include "info_impl_fw.hh"
40#include "item_type.hh"
41
42namespace ost { namespace info {
43
45 friend class InfoGroup;
46public:
47
48
51
53 String GetName() const;
55 void SetName(const String& n);
56
58
62
64
67 void SetValue(const String& val);
68
70
74 Type GetType() const;
75
77 /*
78 will do internal conversion
79 */
80 void SetType(Type t);
81
82 void SetType(int t);
83
85 Real AsFloat() const;
87 int AsInt() const;
89 bool AsBool() const;
92
94 void SetFloat(Real d);
96 void SetInt(int i);
98 void SetBool(bool b);
100 void SetVector(const geom::Vec3& v);
101
103 String GetAttribute(const String& name) const;
105 void SetAttribute(const String& name, const String& value);
107 bool HasAttribute(const String& name) const;
109 void RemoveAttribute(const String& name);
112
114 std::vector<String> GetAttributeList() const;
115
116 bool operator==(const InfoItem& rhs) const;
117 bool operator!=(const InfoItem& rhs) const;
118private:
119 InfoItem(const InfoHandle& root, const ElePtr& impl, Type t=IT_STRING);
120
121 InfoHandle root_;
122 ElePtr impl_;
123 Type type_;
124};
125
127template <typename T>
128T Extract(const info::InfoGroup& g, const String& n)
129{
130 return boost::lexical_cast<T>(g.GetItem(n).GetValue());
131}
132
133// more convenience functions
135int DLLEXPORT_OST_INFO GetIntInfoItem(const InfoGroup& ig, const InfoPath& path, int def);
136bool DLLEXPORT_OST_INFO GetBoolInfoItem(const InfoGroup& ig, const InfoPath& path, bool def);
139
142void DLLEXPORT_OST_INFO SetBoolInfoItem(InfoGroup ig, const InfoPath& path, bool val);
145
146}} // ns
147
148#endif
Three dimensional vector class, using Real precision.
Definition vec3.hh:48
InfoItem GetItem(const InfoPath &path, bool use_defaults=true) const
main info handle
void SetFloat(Real d)
set item value as floating point
bool HasAttribute(const String &name) const
returns true if attribute of this names exists
String GetName() const
retrieve item name
std::vector< String > GetAttributeList() const
returns a list with all attribute names
void SetName(const String &n)
rename item
Real AsFloat() const
return item value as floating point
Type GetType() const
retrieve type
String GetComment() const
get comment just above item
void SetValue(const String &val)
set value of item
void RemoveAttribute(const String &name)
remove attribute of given name
String GetValue() const
retrieve value of item
InfoGroup GetParent() const
retrieve parent info group
void SetInt(int i)
set item value as integer
void SetBool(bool b)
set item value as bool
void SetType(int t)
String GetAttribute(const String &name) const
return attribute of given name
void SetVector(const geom::Vec3 &v)
set item value as 3d vector
bool operator!=(const InfoItem &rhs) const
bool AsBool() const
return item value as boolean
int AsInt() const
return item value as integer
geom::Vec3 AsVector() const
return item value as 3d vector
void SetAttribute(const String &name, const String &value)
set attribute of given name, will be created if it does not yet exist
bool operator==(const InfoItem &rhs) const
void SetType(Type t)
force type
encapsulates path to info groups and items
Definition info_path.hh:44
#define DLLEXPORT_OST_INFO
float Real
Definition base.hh:44
std::string String
Definition base.hh:54
Real DLLEXPORT_OST_INFO GetFloatInfoItem(const InfoGroup &ig, const InfoPath &path, Real def)
void DLLEXPORT_OST_INFO SetBoolInfoItem(InfoGroup ig, const InfoPath &path, bool val)
geom::Vec3 DLLEXPORT_OST_INFO GetVectorInfoItem(const InfoGroup &ig, const InfoPath &path, const geom::Vec3 &def)
int DLLEXPORT_OST_INFO GetIntInfoItem(const InfoGroup &ig, const InfoPath &path, int def)
bool DLLEXPORT_OST_INFO GetBoolInfoItem(const InfoGroup &ig, const InfoPath &path, bool def)
boost::shared_ptr< detail::EleImpl > ElePtr
void DLLEXPORT_OST_INFO SetVectorInfoItem(InfoGroup ig, const InfoPath &path, const geom::Vec3 &val)
T Extract(const info::InfoGroup &g, const String &n)
Convenience function to extract a value from an item.
Definition info_item.hh:128
String DLLEXPORT_OST_INFO GetStringInfoItem(const InfoGroup &ig, const InfoPath &path, const String &def)
void DLLEXPORT_OST_INFO SetIntInfoItem(InfoGroup ig, const InfoPath &path, int val)
void DLLEXPORT_OST_INFO SetStringInfoItem(InfoGroup ig, const InfoPath &path, const String &val)
void DLLEXPORT_OST_INFO SetFloatInfoItem(InfoGroup ig, const InfoPath &path, Real val)
Definition base.dox:1