2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _GD_BDCFF_HELPER
18 #define _GD_BDCFF_HELPER
26 #define BDCFF_VERSION "0.5"
29 * Functor which checks if a string has another string as its prefix.
30 * eg, it will return true for "SlimePermeability=0.1" begins with "SlimePermeability"
31 * The check is case-insensitive!
36 explicit HasAttrib(const std::string
&attrib_
);
37 bool operator()(const std::string
&str
) const;
41 /// A class which splits a BDCFF line read
42 /// into two parts - an attribute name and parameters.
43 /// For example, "SlimePermeability=0.1" is split into
44 /// "SlimePermeability" (attrib) and "0.1" param.
49 explicit AttribParam(const std::string
&str
, char separator
='=');
52 typedef std::list
<std::string
> BdcffSection
;
53 typedef BdcffSection::iterator BdcffSectionIterator
;
54 typedef BdcffSection::const_iterator BdcffSectionConstIterator
;
57 * A structure, which stores the lines of text in a bdcff file; and has a list
58 * of these strings for each section.
60 * The main format of the bdcff file.
61 * Contains: bdcff section; highscore for caveset, map codes, caveset properties, and caves data.
62 * Caves data contains: highscore for cave, cave properties, maybe map, maybe objects, maybe replays, maybe demo (=legacy replay).
66 BdcffSection highscore
;
67 BdcffSection properties
;
70 std::list
<BdcffSection
> replays
;
75 BdcffSection highscore
;
76 BdcffSection mapcodes
;
77 BdcffSection caveset_properties
;
78 std::list
<CaveInfo
> caves
;
82 /** A class which helps outputting BDCFF lines like "Point=x y z".
84 * It stores a name (Point), and can be fed with parameters
85 * using a standard operator<<.
86 * If conversion is ready, the str() member function can be
87 * used to get the BDCFF output.
91 std::ostringstream os
; ///< for conversion
92 std::string name
; ///< name of parameter, eg. Size
93 bool firstparam
; ///< used internally do determine if a space is needed
96 explicit BdcffFormat(const std::string
&f
="");
97 template <typename T
> BdcffFormat
&operator<<(const T
¶m
);
98 void start_new(const std::string
&f
);
99 std::string
str() const;
100 /** cast to string - return the string. */
101 operator std::string() const {
107 * @brief Feed next output parameter to the formatter.
108 * @param param The variable to write.
109 * @return Itself, for linking << a << b << c.
111 template <typename T
>
112 BdcffFormat
&BdcffFormat::operator<<(const T
¶m
) {
113 /* if this is not the first parameter, add a space */