UtiLite
0.3.1
A lite utilities library
|
00001 /* 00002 * utilite is a cross-platform library with 00003 * useful utilities for fast and small developing. 00004 * Copyright (C) 2010 Mathieu Labbe 00005 * 00006 * utilite is free library: you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * utilite 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 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #ifndef UVARIANT_H 00021 #define UVARIANT_H 00022 00023 #include <string> 00024 00028 class UVariant 00029 { 00030 public: 00031 virtual ~UVariant() {} 00032 00033 virtual std::string className() const = 0; 00034 00035 template<class T> 00036 const T * data() const { 00037 if(data_) 00038 return (T*)data_; 00039 return (const T*)constData_; 00040 } 00041 00042 template<class T> 00043 T * takeDataOwnership() { 00044 T * data = (T*)data_; 00045 constData_ = 0; 00046 data_=0; 00047 return data; 00048 } 00049 00050 protected: 00051 UVariant(void * data) : 00052 data_(data), 00053 constData_(0) 00054 {} 00055 00056 UVariant(const void * data) : 00057 data_(0), 00058 constData_(data) 00059 {} 00060 00061 protected: 00062 void * data_; 00063 const void * constData_; 00064 }; 00065 00066 #endif /* UVARIANT_H */