value.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * C++ sphinx search client library
00004  * Copyright (C) 2007  Seznam.cz, a.s.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  * Seznam.cz, a.s.
00021  * Radlicka 2, Praha 5, 15000, Czech Republic
00022  * http://www.seznam.cz, mailto:sphinxclient@firma.seznam.cz
00023  *
00024  *
00025  * $Id: value.h 32 2013-01-21 12:07:00Z honkir $
00026  *
00027  * DESCRIPTION
00028  * SphinxClient header file - attribute value abstraction
00029  *
00030  * AUTHOR
00031  * Jan Kirschner <jan.kirschner@firma.seznam.cz>
00032  *
00033  * HISTORY
00034  * 2007-01-03 (jan.kirschner)
00035  *            First draft.
00036  */
00037 
00039 
00040 #ifndef __SPHINXVALUE_H__
00041 #define __SPHINXVALUE_H__
00042 
00043 #include <vector>
00044 #include <sphinxclient/error.h>
00045 #include <stdint.h>
00046 
00047 namespace Sphinx
00048 {
00049 
00053 enum ValueType_t {
00054     VALUETYPE_UINT32 = 0, 
00055     VALUETYPE_FLOAT = 1,  
00056     VALUETYPE_VECTOR = 2, 
00057     VALUETYPE_UINT64 = 3, 
00058     VALUETYPE_STRING = 4  
00059 };
00060 
00061 class ValueBase_t;
00062 
00070 class Value_t {
00071 protected:
00072     ValueBase_t *value;
00073     void clear();
00074     void makeCopy(const Value_t&);
00075 
00076 public:
00077     Value_t() : value(0) {}
00079     Value_t(uint32_t v);
00081     Value_t(float v);
00083     Value_t(const std::vector<Value_t> &v);
00085     Value_t(uint64_t v);
00087     Value_t(const std::string &v);
00088 
00089     ~Value_t(){ clear(); }
00090 
00092     Value_t(const Value_t &v){ makeCopy(v); }
00094     Value_t & operator = (const Value_t&);
00095 
00098     inline bool isValid() const { return value; }
00099 
00106     ValueType_t getValueType() const;
00107 
00113     operator uint32_t () const throw (ValueTypeError_t);
00114 
00120     operator const std::vector<Value_t>& () const throw (ValueTypeError_t);
00121 
00127     operator float () const throw (ValueTypeError_t);
00128 
00134     operator uint64_t () const throw (ValueTypeError_t);
00135 
00141     operator const std::string & () const throw (ValueTypeError_t);
00142 };//class
00143 
00144 
00145 }//namespace
00146 
00147 #endif