2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef BDCFFHELPER_HPP_INCLUDED
25 #define BDCFFHELPER_HPP_INCLUDED
33 #define BDCFF_VERSION "0.5"
36 * Functor which checks if a string has another string as its prefix.
37 * eg, it will return true for "SlimePermeability=0.1" begins with "SlimePermeability"
38 * The check is case-insensitive!
43 explicit HasAttrib(const std::string
&attrib_
);
44 bool operator()(const std::string
&str
) const;
48 /// A class which splits a BDCFF line read
49 /// into two parts - an attribute name and parameters.
50 /// For example, "SlimePermeability=0.1" is split into
51 /// "SlimePermeability" (attrib) and "0.1" param.
56 explicit AttribParam(const std::string
&str
, char separator
= '=');
59 typedef std::list
<std::string
> BdcffSection
;
60 typedef BdcffSection::iterator BdcffSectionIterator
;
61 typedef BdcffSection::const_iterator BdcffSectionConstIterator
;
64 * A structure, which stores the lines of text in a bdcff file; and has a list
65 * of these strings for each section.
67 * The main format of the bdcff file.
68 * Contains: bdcff section; highscore for caveset, map codes, caveset properties, and caves data.
69 * Caves data contains: highscore for cave, cave properties, maybe map, maybe objects, maybe replays, maybe demo (=legacy replay).
73 BdcffSection highscore
;
74 BdcffSection properties
;
77 std::list
<BdcffSection
> replays
;
82 BdcffSection highscore
;
83 BdcffSection mapcodes
;
84 BdcffSection caveset_properties
;
85 std::list
<CaveInfo
> caves
;
89 /** A class which helps outputting BDCFF lines like "Point=x y z".
91 * It stores a name (Point), and can be fed with parameters
92 * using a standard operator<<.
93 * If conversion is ready, the str() member function can be
94 * used to get the BDCFF output.
98 std::ostringstream os
; ///< for conversion
99 std::string name
; ///< name of parameter, eg. Size
100 bool firstparam
; ///< used internally do determine if a space is needed
103 explicit BdcffFormat(const std::string
&f
= "");
104 template <typename T
> BdcffFormat
&operator<<(const T
¶m
);
105 void start_new(const std::string
&f
);
106 std::string
str() const;
107 /** cast to string - return the string. */
108 operator std::string() const {
114 * @brief Feed next output parameter to the formatter.
115 * @param param The variable to write.
116 * @return Itself, for linking << a << b << c.
118 template <typename T
>
119 BdcffFormat
&BdcffFormat::operator<<(const T
¶m
) {
120 /* if this is not the first parameter, add a space */