Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/lib/gui/gui_saveable.cc @ 10699

Last change on this file since 10699 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
17
18#include "gui_saveable.h"
19#include "gui.h"
20#include "parser/preferences/preferences.h"
21
22#include "debug.h"
23
24namespace OrxGui
25{
26
27  /**
28   * standard constructor
29  */
30  Saveable::Saveable (const std::string& optionName, SaveableGroup* group, const MultiType& defaultValue)
31  : BaseObject(optionName)
32  {
33    this->bSaveable = false;
34    this->_defaultValue = defaultValue;
35
36    assert(group != NULL);
37    this->group = group;
38    this->group->addSaveable(this);
39
40  }
41
42
43  /**
44   * standard deconstructor
45  */
46  Saveable::~Saveable ()
47  {
48    this->group->removeSaveable(this);
49    // delete what has to be deleted here
50  }
51
52
53  void Saveable::makeSaveable()
54  {
55    this->bSaveable = true;
56
57  }
58
59
60  void Saveable::load()
61  {
62    this->value() = Preferences::getInstance()->getMultiType(this->group->getCName(), this->getCName(), this->_defaultValue);
63    PRINTF(4)("Loaded to '%s' of group '%s' value '%s'\n", this->getCName(), this->group->getCName(), this->value().getCString());
64  }
65
66  void Saveable::save()
67  {
68    Preferences::getInstance()->setMultiType(this->group->getCName(), this->getCName(), this->value() );
69    PRINTF(4)("Saved to '%s' of group '%s' value '%s'\n", this->getCName(), this->group->getCName(), this->value().getCString());
70  }
71
72
73
74
75  SaveableGroup::SaveableGroup(const std::string& groupName, OrxGui::Gui* gui)
76      : BaseObject(groupName)
77  {
78    assert (gui != NULL);
79    this->gui = gui;
80
81    this->gui->addSaveableGroup(this);
82    //this->mainWidget = NULL;
83  }
84
85
86
87  SaveableGroup::~SaveableGroup()
88  {
89    this->gui->removeSaveableGroup(this);
90  }
91
92
93  /**
94   * @brief Adds a Saveable to the List.
95   * @param saveable the saveable to add.
96   */
97  void SaveableGroup::addSaveable(Saveable* saveable)
98  {
99    if (std::find(this->saveables.begin(), this->saveables.end(), saveable) == this->saveables.end())
100      this->saveables.push_back(saveable);
101  }
102
103  /**
104   * @brief Removes a Saveable from the List.
105   * @param saveable the saveable to remove.
106   */
107  void SaveableGroup::removeSaveable(Saveable* saveable)
108  {
109    std::vector<Saveable*>::iterator delSav = std::find(this->saveables.begin(), this->saveables.end(), saveable);
110    if (delSav != this->saveables.end())
111      this->saveables.erase(delSav);
112  }
113
114
115  /**
116   * @brief load the value onto the Group.
117   * @param value the Value to load.
118   */
119  void SaveableGroup::load()
120  {
121    std::vector<Saveable*>::iterator elem;
122    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
123      (*elem)->load();
124  }
125
126  /**
127   * @brief save the value from the Group
128   * @returns nothing.
129   */
130  void SaveableGroup::save()
131  {
132    std::vector<Saveable*>::iterator elem;
133    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
134      (*elem)->save();
135  }
136
137
138
139
140}
Note: See TracBrowser for help on using the repository browser.