libIntegra
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
value.h
Go to the documentation of this file.
1 /* libIntegra modular audio framework
2  *
3  * Copyright (C) 2007 Birmingham City University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18  * USA.
19  */
20 
26 #ifndef INTEGRA_VALUE_PRIVATE_H
27 #define INTEGRA_VALUE_PRIVATE_H
28 
29 #include <unordered_map>
30 
31 #include "common_typedefs.h"
32 
33 
34 namespace integra_api
35 {
42  class INTEGRA_API CValue
43  {
44  protected:
45  CValue();
46 
47  public:
48 
49  virtual ~CValue();
50 
52  enum type
53  {
56 
59 
61  STRING
62  };
63 
65  virtual type get_type() const = 0;
66 
74  virtual operator int() const;
75 
80  virtual operator float() const;
81 
86  virtual operator const string &() const;
87 
92  virtual CValue *clone() const = 0;
93 
98  virtual void convert( CValue &conversion_target ) const = 0;
99 
105  virtual bool is_equal( const CValue &other ) const = 0;
106 
116  virtual float get_distance( const CValue &other ) const = 0;
117 
120  virtual string get_as_string() const = 0;
121 
125  virtual void set_from_string( const string &source ) = 0;
126 
133  CValue *transmogrify( type new_type ) const;
134 
140  static CValue *factory( type new_type );
141 
144  static const char *get_type_name( type value_type );
145 
151  static int type_to_ixd_code( type value_type );
152 
158  static type ixd_code_to_type( int ixd_code );
159 
160  private:
161 
162  void handle_incorrect_cast( type cast_target ) const;
163  };
164 
165 
169  class INTEGRA_API CIntegerValue : public CValue
170  {
171  public:
172 
173  CIntegerValue();
174  CIntegerValue( int value );
175  ~CIntegerValue();
176 
177  type get_type() const;
178 
179  operator int() const;
180  const CIntegerValue &operator= ( const CIntegerValue &to_copy );
181 
182  CValue *clone() const;
183  void convert( CValue &conversion_target ) const;
184 
185  bool is_equal( const CValue &other ) const;
186  float get_distance( const CValue &other ) const;
187 
188  string get_as_string() const;
189  void set_from_string( const string &source );
190 
191  private:
192 
193  int m_value;
194  };
195 
196 
200  class INTEGRA_API CFloatValue : public CValue
201  {
202  public:
203 
204  CFloatValue();
205  CFloatValue( float value );
206  ~CFloatValue();
207 
208  type get_type() const;
209 
210  operator float() const;
211  const CFloatValue &operator= ( const CFloatValue &to_copy );
212 
213  CValue *clone() const;
214  void convert( CValue &conversion_target ) const;
215 
216  bool is_equal( const CValue &other ) const;
217  float get_distance( const CValue &other ) const;
218 
219  string get_as_string() const;
220  void set_from_string( const string &source );
221 
222  private:
223 
224  float m_value;
225  };
226 
227 
231  class INTEGRA_API CStringValue : public CValue
232  {
233  public:
234 
235  CStringValue();
236  CStringValue( const string &value );
237  ~CStringValue();
238 
239  type get_type() const;
240 
241  operator const string &() const;
242  const CStringValue &operator= ( const CStringValue &to_copy );
243 
244  CValue *clone() const;
245  void convert( CValue &conversion_target ) const;
246 
247  bool is_equal( const CValue &other ) const;
248  float get_distance( const CValue &other ) const;
249 
250  string get_as_string() const;
251  void set_from_string( const string &source );
252 
253  private:
254 
255  /* calculate levenshtein distance between two strings. */
256  static int levenshtein_distance( const char *string1, const char *string2 );
257 
258  string m_value;
259  };
260 
261 
263  typedef std::unordered_map<string, CValue *> value_map;
264 
266  typedef std::unordered_set<CValue *> value_set;
267 }
268 
269 
270 #endif
Definition: value.h:55
type
Definition: value.h:52
Base class for the concrete value classes CIntegerValue, CFloatValue and CStringValue.
Definition: value.h:42
Definition: value.h:58
Represents a float value.
Definition: value.h:200
Represents a string value.
Definition: value.h:231
Represents an integer value.
Definition: value.h:169
#defines and typedefs used throughout the application