vrheights
changeset 12:cb97ea43709b
fixed line endings
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 03 Oct 2014 23:11:43 +0300 |
parents | 537db3079134 |
children | 0168104ec568 |
files | src/game_var.cc src/game_var.h |
diffstat | 2 files changed, 175 insertions(+), 175 deletions(-) [+] |
line diff
1.1 --- a/src/game_var.cc Fri Oct 03 23:11:23 2014 +0300 1.2 +++ b/src/game_var.cc Fri Oct 03 23:11:43 2014 +0300 1.3 @@ -1,143 +1,143 @@ 1.4 -#include <string.h> 1.5 -#include <map> 1.6 -#include "game_var.h" 1.7 - 1.8 -static std::map<std::string, GameVariable> gvars; 1.9 - 1.10 -GameVariable::GameVariable() 1.11 -{ 1.12 - num_val = 0.0f; 1.13 - bool_val = false; 1.14 -} 1.15 - 1.16 -std::string GameVariable::to_str() const 1.17 -{ 1.18 - char buf[128]; 1.19 - 1.20 - switch(type) { 1.21 - case GameVariable::STR: 1.22 - return val; 1.23 - case GameVariable::BOOL: 1.24 - return bool_val ? "true" : "false"; 1.25 - case GameVariable::NUMBER: 1.26 - sprintf(buf, "%g", num_val); 1.27 - return buf; 1.28 - } 1.29 - return "<unknown>"; 1.30 -} 1.31 - 1.32 -void set_gvar(const GameVariable &var) 1.33 -{ 1.34 - gvars[var.name] = var; 1.35 -} 1.36 - 1.37 -void set_gvar_str(const char *name, const char *val) 1.38 -{ 1.39 - GameVariable v; 1.40 - v.name = name; 1.41 - v.val = val; 1.42 - v.type = GameVariable::STR; 1.43 - set_gvar(v); 1.44 -} 1.45 - 1.46 -void set_gvar_num(const char *name, float val) 1.47 -{ 1.48 - GameVariable v; 1.49 - v.name = name; 1.50 - v.num_val = val; 1.51 - v.type = GameVariable::NUMBER; 1.52 - set_gvar(v); 1.53 -} 1.54 - 1.55 -void set_gvar_bool(const char *name, bool val) 1.56 -{ 1.57 - GameVariable v; 1.58 - v.name = name; 1.59 - v.bool_val = val; 1.60 - v.type = GameVariable::BOOL; 1.61 - set_gvar(v); 1.62 -} 1.63 - 1.64 -static char *strip_whitespace(char *s) 1.65 -{ 1.66 - while(*s && isspace(*s)) ++s; 1.67 - if(*s == 0) return s; 1.68 - 1.69 - char *endp = s + strlen(s) - 1; 1.70 - while(endp > s && isspace(*endp)) { 1.71 - *endp-- = 0; 1.72 - } 1.73 - return s; 1.74 -} 1.75 - 1.76 -static int strccmp(const char *a, const char *b) 1.77 -{ 1.78 - while(*a && *b) { 1.79 - int diff = tolower(*a) - tolower(*b); 1.80 - if(diff != 0) return diff; 1.81 - ++a; 1.82 - ++b; 1.83 - } 1.84 - if(*a == 0 && *b == 0) return 0; 1.85 - return *a == 0 ? -1 : 1; 1.86 -} 1.87 - 1.88 -int set_gvar_parse(const char *name, const char *val) 1.89 -{ 1.90 - char *endp, *valstr = (char*)alloca(strlen(val) + 1); 1.91 - strcpy(valstr, val); 1.92 - valstr = strip_whitespace(valstr); 1.93 - 1.94 - float fval = strtod(valstr, &endp); 1.95 - if(endp != valstr && *endp == 0) { 1.96 - set_gvar_num(name, fval); 1.97 - return GameVariable::NUMBER; 1.98 - } 1.99 - 1.100 - if(strccmp(valstr, "true") == 0 || strccmp(valstr, "yes") == 0) { 1.101 - set_gvar_bool(name, true); 1.102 - return GameVariable::BOOL; 1.103 - } 1.104 - if(strccmp(valstr, "false") == 0 || strccmp(valstr, "no") == 0) { 1.105 - set_gvar_bool(name, false); 1.106 - return GameVariable::BOOL; 1.107 - } 1.108 - set_gvar_str(name, val); 1.109 - return GameVariable::STR; 1.110 -} 1.111 - 1.112 -GameVariable &get_gvar(const char *name) 1.113 -{ 1.114 - return gvars[name]; 1.115 -} 1.116 - 1.117 -const char *get_gvar_str(const char *name) 1.118 -{ 1.119 - return gvars[name].val.c_str(); 1.120 -} 1.121 - 1.122 -float get_gvar_num(const char *name) 1.123 -{ 1.124 - return gvars[name].num_val; 1.125 -} 1.126 - 1.127 -bool get_gvar_bool(const char *name) 1.128 -{ 1.129 - return gvars[name].bool_val; 1.130 -} 1.131 - 1.132 -bool have_gvar(const char *name) 1.133 -{ 1.134 - return gvars.find(std::string(name)) != gvars.end(); 1.135 -} 1.136 - 1.137 -std::list<std::string> get_gvar_list() 1.138 -{ 1.139 - std::list<std::string> res; 1.140 - 1.141 - std::map<std::string, GameVariable>::const_iterator it = gvars.begin(); 1.142 - while(it != gvars.end()) { 1.143 - res.push_back((it++)->first); 1.144 - } 1.145 - return res; 1.146 -} 1.147 +#include <string.h> 1.148 +#include <map> 1.149 +#include "game_var.h" 1.150 + 1.151 +static std::map<std::string, GameVariable> gvars; 1.152 + 1.153 +GameVariable::GameVariable() 1.154 +{ 1.155 + num_val = 0.0f; 1.156 + bool_val = false; 1.157 +} 1.158 + 1.159 +std::string GameVariable::to_str() const 1.160 +{ 1.161 + char buf[128]; 1.162 + 1.163 + switch(type) { 1.164 + case GameVariable::STR: 1.165 + return val; 1.166 + case GameVariable::BOOL: 1.167 + return bool_val ? "true" : "false"; 1.168 + case GameVariable::NUMBER: 1.169 + sprintf(buf, "%g", num_val); 1.170 + return buf; 1.171 + } 1.172 + return "<unknown>"; 1.173 +} 1.174 + 1.175 +void set_gvar(const GameVariable &var) 1.176 +{ 1.177 + gvars[var.name] = var; 1.178 +} 1.179 + 1.180 +void set_gvar_str(const char *name, const char *val) 1.181 +{ 1.182 + GameVariable v; 1.183 + v.name = name; 1.184 + v.val = val; 1.185 + v.type = GameVariable::STR; 1.186 + set_gvar(v); 1.187 +} 1.188 + 1.189 +void set_gvar_num(const char *name, float val) 1.190 +{ 1.191 + GameVariable v; 1.192 + v.name = name; 1.193 + v.num_val = val; 1.194 + v.type = GameVariable::NUMBER; 1.195 + set_gvar(v); 1.196 +} 1.197 + 1.198 +void set_gvar_bool(const char *name, bool val) 1.199 +{ 1.200 + GameVariable v; 1.201 + v.name = name; 1.202 + v.bool_val = val; 1.203 + v.type = GameVariable::BOOL; 1.204 + set_gvar(v); 1.205 +} 1.206 + 1.207 +static char *strip_whitespace(char *s) 1.208 +{ 1.209 + while(*s && isspace(*s)) ++s; 1.210 + if(*s == 0) return s; 1.211 + 1.212 + char *endp = s + strlen(s) - 1; 1.213 + while(endp > s && isspace(*endp)) { 1.214 + *endp-- = 0; 1.215 + } 1.216 + return s; 1.217 +} 1.218 + 1.219 +static int strccmp(const char *a, const char *b) 1.220 +{ 1.221 + while(*a && *b) { 1.222 + int diff = tolower(*a) - tolower(*b); 1.223 + if(diff != 0) return diff; 1.224 + ++a; 1.225 + ++b; 1.226 + } 1.227 + if(*a == 0 && *b == 0) return 0; 1.228 + return *a == 0 ? -1 : 1; 1.229 +} 1.230 + 1.231 +int set_gvar_parse(const char *name, const char *val) 1.232 +{ 1.233 + char *endp, *valstr = (char*)alloca(strlen(val) + 1); 1.234 + strcpy(valstr, val); 1.235 + valstr = strip_whitespace(valstr); 1.236 + 1.237 + float fval = strtod(valstr, &endp); 1.238 + if(endp != valstr && *endp == 0) { 1.239 + set_gvar_num(name, fval); 1.240 + return GameVariable::NUMBER; 1.241 + } 1.242 + 1.243 + if(strccmp(valstr, "true") == 0 || strccmp(valstr, "yes") == 0) { 1.244 + set_gvar_bool(name, true); 1.245 + return GameVariable::BOOL; 1.246 + } 1.247 + if(strccmp(valstr, "false") == 0 || strccmp(valstr, "no") == 0) { 1.248 + set_gvar_bool(name, false); 1.249 + return GameVariable::BOOL; 1.250 + } 1.251 + set_gvar_str(name, val); 1.252 + return GameVariable::STR; 1.253 +} 1.254 + 1.255 +GameVariable &get_gvar(const char *name) 1.256 +{ 1.257 + return gvars[name]; 1.258 +} 1.259 + 1.260 +const char *get_gvar_str(const char *name) 1.261 +{ 1.262 + return gvars[name].val.c_str(); 1.263 +} 1.264 + 1.265 +float get_gvar_num(const char *name) 1.266 +{ 1.267 + return gvars[name].num_val; 1.268 +} 1.269 + 1.270 +bool get_gvar_bool(const char *name) 1.271 +{ 1.272 + return gvars[name].bool_val; 1.273 +} 1.274 + 1.275 +bool have_gvar(const char *name) 1.276 +{ 1.277 + return gvars.find(std::string(name)) != gvars.end(); 1.278 +} 1.279 + 1.280 +std::list<std::string> get_gvar_list() 1.281 +{ 1.282 + std::list<std::string> res; 1.283 + 1.284 + std::map<std::string, GameVariable>::const_iterator it = gvars.begin(); 1.285 + while(it != gvars.end()) { 1.286 + res.push_back((it++)->first); 1.287 + } 1.288 + return res; 1.289 +}
2.1 --- a/src/game_var.h Fri Oct 03 23:11:23 2014 +0300 2.2 +++ b/src/game_var.h Fri Oct 03 23:11:43 2014 +0300 2.3 @@ -1,32 +1,32 @@ 2.4 -#ifndef GAME_VAR_H_ 2.5 -#define GAME_VAR_H_ 2.6 - 2.7 -#include <string> 2.8 -#include <list> 2.9 - 2.10 -struct GameVariable { 2.11 - enum { NUMBER, BOOL, STR } type; 2.12 - std::string name, val; 2.13 - float num_val; 2.14 - bool bool_val; 2.15 - 2.16 - GameVariable(); 2.17 - std::string to_str() const; 2.18 -}; 2.19 - 2.20 -void set_gvar(const GameVariable &var); 2.21 -void set_gvar_str(const char *name, const char *val); 2.22 -void set_gvar_num(const char *name, float val); 2.23 -void set_gvar_bool(const char *name, bool val); 2.24 -int set_gvar_parse(const char *name, const char *val); 2.25 - 2.26 -GameVariable &get_gvar(const char *name); 2.27 -const char *get_gvar_str(const char *name); 2.28 -float get_gvar_num(const char *name); 2.29 -bool get_gvar_bool(const char *name); 2.30 - 2.31 -bool have_gvar(const char *name); 2.32 - 2.33 -std::list<std::string> get_gvar_list(); 2.34 - 2.35 -#endif // GAME_VAR_H_ 2.36 +#ifndef GAME_VAR_H_ 2.37 +#define GAME_VAR_H_ 2.38 + 2.39 +#include <string> 2.40 +#include <list> 2.41 + 2.42 +struct GameVariable { 2.43 + enum { NUMBER, BOOL, STR } type; 2.44 + std::string name, val; 2.45 + float num_val; 2.46 + bool bool_val; 2.47 + 2.48 + GameVariable(); 2.49 + std::string to_str() const; 2.50 +}; 2.51 + 2.52 +void set_gvar(const GameVariable &var); 2.53 +void set_gvar_str(const char *name, const char *val); 2.54 +void set_gvar_num(const char *name, float val); 2.55 +void set_gvar_bool(const char *name, bool val); 2.56 +int set_gvar_parse(const char *name, const char *val); 2.57 + 2.58 +GameVariable &get_gvar(const char *name); 2.59 +const char *get_gvar_str(const char *name); 2.60 +float get_gvar_num(const char *name); 2.61 +bool get_gvar_bool(const char *name); 2.62 + 2.63 +bool have_gvar(const char *name); 2.64 + 2.65 +std::list<std::string> get_gvar_list(); 2.66 + 2.67 +#endif // GAME_VAR_H_