UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
keyvaluepair.h
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 Copyright (C) 1997-2001 Id Software, Inc.
10 
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 See the GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 
26 */
27 
28 #pragma once
29 
30 #include "mathlib.h"
31 #include <stdio.h>
32 
38 class KeyValuePair {
39 private:
40  const char* _keyStr;
41  const char* _valStr;
42 public:
43  KeyValuePair (const char* keyStr, const char* valStr) {
44  _keyStr = keyStr;
45  _valStr = valStr;
46  }
47  inline void set (const char* keyStr, const char* valStr) {
48  _keyStr = keyStr;
49  _valStr = valStr;
50  }
51  inline bool isKey(const char* name) const {
52  return !strcmp(_keyStr, name);
53  }
54  inline float asFloat () const {
55  return atof(_valStr);
56  }
57  inline int asInt () const {
58  return atoi(_valStr);
59  }
60  inline bool asBool () const {
61  return asInt() != 0 ? true : false;
62  }
63  inline const char* asString () const {
64  return _valStr;
65  }
66  void asVec3 (vec3_t vec) const {
67  if (sscanf(_valStr, "%f %f %f", &vec[0], &vec[1], &vec[2]) != 3)
68  VectorCopy(vec3_origin, vec);
69  }
70 };
#define VectorCopy(src, dest)
Definition: vector.h:51
void asVec3(vec3_t vec) const
Definition: keyvaluepair.h:66
KeyValuePair(const char *keyStr, const char *valStr)
Definition: keyvaluepair.h:43
A pair of strings representing a key and a value The value string can be trimmed and rendered in the ...
Definition: keyvaluepair.h:38
int asInt() const
Definition: keyvaluepair.h:57
const char * _keyStr
Definition: keyvaluepair.h:40
const vec3_t vec3_origin
Definition: mathlib.cpp:35
bool asBool() const
Definition: keyvaluepair.h:60
float asFloat() const
Definition: keyvaluepair.h:54
void set(const char *keyStr, const char *valStr)
Definition: keyvaluepair.h:47
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
bool isKey(const char *name) const
Definition: keyvaluepair.h:51
const char * asString() const
Definition: keyvaluepair.h:63
vec_t vec3_t[3]
Definition: ufotypes.h:39
const char * _valStr
Definition: keyvaluepair.h:41