Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / range_manager.h
blob338578ce465ab76f2db5f966ca8fc517de62a5eb
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef RANGE_MANAGER_H
18 #define RANGE_MANAGER_H
20 #include <map>
21 #include <string>
23 #include "nel/misc/stream.h"
25 /** This class records the ranges used for edition (for a given slider).
26 * It enables the user to set the range that match best what he wants
27 * full ASCII names are used as identifier
30 template <class T> class CRangeManager
32 public:
33 /** retrieve the range used for a given ID.
34 * If the ID wasn't present, a new entry is created, and the given values are returned
36 static std::pair<T, T> GetRange(const std::string &id, const T &minRange, const T &maxRange)
38 nlassert(id != "");
39 if (_RangeMap.count(id) == 0) // not present yet ?
41 _RangeMap[id] = std::pair<T, T>(minRange, maxRange);
43 return _RangeMap[id];
46 /** the same but no default values are provided. An assertion occurs if not present.
47 * In release build, the entrie is created, but with uninitialized values ...
50 static std::pair<T, T> GetRange(const std::string &id)
52 nlassert(id != "");
53 return _RangeMap[id];
56 /// set a new value for the given range
58 static void SetRange(const std::string &id, const T &minRange, const T &maxRange)
60 nlassert(id != "");
61 _RangeMap[id] = std::pair<T, T>(minRange, maxRange);
64 /// serialization
65 static void serial(NLMISC::IStream &f)
67 uint32 size;
68 if (!f.isReading())
70 size = _RangeMap.size();
71 f.serial(size);
72 for (TRangeMap::const_iterator it = _RangeMap.begin(); it != _RangeMap.end(); ++it)
74 std::string s = it->first;
75 f.serial(s);
76 std::pair<T , T> value = it->second;
77 f.serial(value.first);
78 f.serial(value.second);
81 else
83 _RangeMap.clear();
84 f.serial(size);
85 while (size --)
87 std::string id;
88 std::pair<T , T> value;
89 f.serial(id);
90 f.serial(value.first);
91 f.serial(value.second);
92 _RangeMap[id] = value;
97 typedef std::map< std::string, std::pair<T, T> > TRangeMap;
99 protected:
101 // the map that contains the ID, and their range values
102 static TRangeMap _RangeMap;
109 #endif