Result.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  * Copyright (C) 2009-2010 Cassio Neri Moreira
00004  *
00005  * This file is part of the KeyValue library.
00006  *
00007  * The KeyValue library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or (at
00010  * your option) any later version.
00011  *
00012  * The KeyValue library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00015  * Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with KeyValue. If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  **************************************************************************/
00021 
00028 #ifndef KEYVALUE_VALUE_RESULT_H_
00029 #define KEYVALUE_VALUE_RESULT_H_
00030 
00031 #include <iosfwd>
00032 
00033 #include <boost/variant.hpp>
00034 
00035 #include "keyvalue/extern/SharedPtr.h"
00036 #include "keyvalue/value/Value.h"
00037 
00038 namespace keyvalue {
00039 namespace value {
00040 
00053 typedef shared_ptr<void> ObjectPtr;
00054 
00060 class Result {
00061 
00062 public:
00063 
00064   typedef boost::variant<ObjectPtr, Value> DataType_;
00065 
00069   Result();
00070 
00078   Result(const DataType_& data);
00079 
00087   template<typename Rhs>
00088   Result(const Rhs& rhs);
00089 
00099   template<typename Rhs>
00100   Result&
00101   operator=(const Rhs& rhs);
00102 
00109   ObjectPtr
00110   getObjectPtr() const;
00111 
00115   ObjectPtr
00116   getObjectPtr();
00117 
00124   const Value*
00125   getValue() const;
00126 
00130   Value*
00131   getValue();
00132 
00133 private:
00134 
00135   DataType_ data_;
00136 
00137 }; // class Result
00138 
00142 std::ostream&
00143 operator<<(std::ostream& os, const Result& rhs);
00144 
00158 template<typename Rhs>
00159 struct Parent;
00160 
00161 template<>
00162 struct Parent<Result::DataType_> {
00163   typedef Result Type_;
00164 };
00165 
00166 template<>
00167 struct Parent<ObjectPtr> {
00168   typedef Result::DataType_ Type_;
00169 };
00170 
00171 template<typename T>
00172 struct Parent<shared_ptr<T> > {
00173   typedef ObjectPtr Type_;
00174 };
00175 
00176 template<typename T>
00177 struct Parent<T*> {
00178   typedef shared_ptr<T> Type_;
00179 };
00180 
00181 template<>
00182 struct Parent<Value> {
00183   typedef Result::DataType_ Type_;
00184 };
00185 
00186 /*--------------------------------------------------------------------------
00187  * Result()
00188  *------------------------------------------------------------------------*/
00189 
00190 template<typename Rhs>
00191 Result::Result(const Rhs& rhs) :
00192   data_(Result(typename Parent<Rhs>::Type_(rhs)).data_) {
00197 }
00198 
00199 /*--------------------------------------------------------------------------
00200  * operator=()
00201  *------------------------------------------------------------------------*/
00202 
00203 template<typename Rhs>
00204 Result&
00205 Result::operator=(const Rhs& rhs) {
00210   return *this = typename Parent<Rhs>::Type_(rhs);
00211 }
00212 
00213 } // namespace value
00214 } // namespace keyvalue
00215 
00216 #endif // KEYVALUE_VALUE_RESULT_H_

Generated on Sat Mar 20 15:08:29 2010 for KeyValue by  doxygen 1.6.1