3
* Copyright (C) 2006 Fabien Chereau
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "StelModule.hpp"
22
#include "InitParser.hpp"
23
#include "StelApp.hpp"
25
/*************************************************************************
26
Get the version of the module, default is stellarium main version
27
*************************************************************************/
28
string StelModule::getModuleVersion() const
30
return PACKAGE_VERSION;
33
/*************************************************************************
34
Init itself from a .ini file
35
*************************************************************************/
36
void StelModule::loadProperties(const string& iniFile)
41
std::cout << "Loading properties for module " << conf.get_str(getModuleID()+":version") << std::endl;
43
std::map<string, propertyAccessor>::const_iterator iter;
44
for(iter=properties.begin();iter!=properties.end();++iter)
46
conf.set_str(getModuleID()+":"+(*iter).first, getPropertyStr((*iter).first));
51
//! Save itself into a .ini file for subsequent reload (don't modify the other entries)
52
void StelModule::saveProperties(const string& iniFile) const
57
conf.set_str(getModuleID()+":version", getModuleVersion());
59
std::map<string, propertyAccessor>::const_iterator iter;
60
for(iter=properties.begin();iter!=properties.end();++iter)
62
conf.set_str(getModuleID()+":"+(*iter).first, getPropertyStr((*iter).first));
67
//! Get a property value as string: try to cast the value as a bool, int, double, string, Vec3d
68
string StelModule::getPropertyStr(const string& key) const
70
std::ostringstream oss;
71
propertyAccessor p = getAccessor(key);
83
catch (boost::bad_any_cast)
89
catch (boost::bad_any_cast)
93
oss << p.get<double>();
95
catch (boost::bad_any_cast)
99
oss << p.get<string>();
101
catch (boost::bad_any_cast)
105
oss << p.get<Vec3d>();
107
catch (boost::bad_any_cast)
109
std::cerr << "Error while getting property \"" << key << "\", can't find matching type." << std::endl;
119
//! Set a property value from a string: try to cast the value as a bool, int, double, string, Vec3d
120
void StelModule::setPropertyStr(const string& key, const string& value)
122
propertyAccessor p = getAccessor(key);
125
p.set<bool>(value=="true");
126
if (value!="true" && value!="false")
128
std::cerr << "Error while setting property \"" << key << "\" to value \""<< value <<"\", boolean value can be \"true\" or \"false\"." << std::endl;
131
catch (boost::bad_any_cast)
135
p.set<string>(value);
137
catch (boost::bad_any_cast)
141
istringstream iss(value);
146
catch (boost::bad_any_cast)
150
istringstream iss(value);
155
catch (boost::bad_any_cast)
157
std::cerr << "Error while setting property \"" << key << "\" to value \""<< value <<"\", can't find matching type." << std::endl;