Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gui_saveable.cc @ 10765

Last change on this file since 10765 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
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[7140]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[7635]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
[1853]17
[7140]18#include "gui_saveable.h"
[7555]19#include "gui.h"
[9869]20#include "parser/preferences/preferences.h"
[1853]21
[8362]22#include "debug.h"
23
[7447]24namespace OrxGui
25{
[1853]26
[7447]27  /**
28   * standard constructor
29  */
[7632]30  Saveable::Saveable (const std::string& optionName, SaveableGroup* group, const MultiType& defaultValue)
[7479]31  : BaseObject(optionName)
[7447]32  {
33    this->bSaveable = false;
[7632]34    this->_defaultValue = defaultValue;
[7479]35
[7595]36    assert(group != NULL);
[7555]37    this->group = group;
38    this->group->addSaveable(this);
39
[7447]40  }
[1856]41
[4320]42
[7447]43  /**
44   * standard deconstructor
45  */
[7480]46  Saveable::~Saveable ()
[7447]47  {
[7555]48    this->group->removeSaveable(this);
[7447]49    // delete what has to be deleted here
50  }
[1853]51
52
[7480]53  void Saveable::makeSaveable()
[7447]54  {
55    this->bSaveable = true;
[7143]56
[7447]57  }
[7143]58
59
[7598]60  void Saveable::load()
[7595]61  {
[9406]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());
[7595]64  }
65
[7598]66  void Saveable::save()
[7595]67  {
[9406]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());
[7595]70  }
71
72
73
74
[7549]75  SaveableGroup::SaveableGroup(const std::string& groupName, OrxGui::Gui* gui)
[7555]76      : BaseObject(groupName)
[7447]77  {
[7555]78    assert (gui != NULL);
79    this->gui = gui;
[7549]80
[7555]81    this->gui->addSaveableGroup(this);
82    //this->mainWidget = NULL;
[7447]83  }
[7143]84
85
86
[7480]87  SaveableGroup::~SaveableGroup()
[7447]88  {
[7555]89    this->gui->removeSaveableGroup(this);
90  }
[7447]91
[7555]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);
[7447]101  }
102
[7555]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   */
[7598]119  void SaveableGroup::load()
[7595]120  {
[7598]121    std::vector<Saveable*>::iterator elem;
122    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
123      (*elem)->load();
[7595]124  }
[7493]125
[7555]126  /**
127   * @brief save the value from the Group
128   * @returns nothing.
129   */
[7598]130  void SaveableGroup::save()
[7600]131  {
132    std::vector<Saveable*>::iterator elem;
133    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
134      (*elem)->save();
135  }
[7493]136
137
138
[7447]139
[7143]140}
Note: See TracBrowser for help on using the repository browser.