1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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
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
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
)
39 if (_RangeMap
.count(id
) == 0) // not present yet ?
41 _RangeMap
[id
] = std::pair
<T
, T
>(minRange
, maxRange
);
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
)
56 /// set a new value for the given range
58 static void SetRange(const std::string
&id
, const T
&minRange
, const T
&maxRange
)
61 _RangeMap
[id
] = std::pair
<T
, T
>(minRange
, maxRange
);
65 static void serial(NLMISC::IStream
&f
)
70 size
= _RangeMap
.size();
72 for (TRangeMap::const_iterator it
= _RangeMap
.begin(); it
!= _RangeMap
.end(); ++it
)
74 std::string s
= it
->first
;
76 std::pair
<T
, T
> value
= it
->second
;
77 f
.serial(value
.first
);
78 f
.serial(value
.second
);
88 std::pair
<T
, T
> value
;
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
;
101 // the map that contains the ID, and their range values
102 static TRangeMap _RangeMap
;