Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

DataValue.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Stephan Aiche$
00032 // $Authors: Marc Sturm $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_DATASTRUCTURES_DATAVALUE_H
00036 #define OPENMS_DATASTRUCTURES_DATAVALUE_H
00037 
00038 #include <OpenMS/CONCEPT/Exception.h>
00039 #include <OpenMS/DATASTRUCTURES/String.h>
00040 #include <OpenMS/DATASTRUCTURES/StringList.h>
00041 #include <OpenMS/DATASTRUCTURES/IntList.h>
00042 #include <OpenMS/DATASTRUCTURES/DoubleList.h>
00043 #include <QtCore/QString>
00044 
00045 namespace OpenMS
00046 {
00047 
00057   class OPENMS_DLLAPI DataValue
00058   {
00059 
00060 public:
00061 
00063     static const DataValue EMPTY;
00064 
00066     enum DataType
00067     {
00068       STRING_VALUE, 
00069       INT_VALUE, 
00070       DOUBLE_VALUE, 
00071       STRING_LIST, 
00072       INT_LIST, 
00073       DOUBLE_LIST, 
00074       EMPTY_VALUE 
00075     };
00076 
00078 
00079 
00080     DataValue();
00082     DataValue(const char*);
00084     DataValue(const std::string&);
00086     DataValue(const String&);
00088     DataValue(const QString&);
00090     DataValue(const StringList&);
00092     DataValue(const IntList&);
00094     DataValue(const DoubleList&);
00096     DataValue(long double);
00098     DataValue(double);
00100     DataValue(float);
00102     DataValue(short int);
00104     DataValue(unsigned short int);
00106     DataValue(int);
00108     DataValue(unsigned);
00110     DataValue(long int);
00112     DataValue(unsigned long);
00114     DataValue(long long);
00116     DataValue(unsigned long long);
00118     DataValue(const DataValue&);
00120     virtual ~DataValue();
00122 
00126 
00127 
00133     operator std::string() const;
00134 
00140     operator StringList() const;
00141 
00147     operator IntList() const;
00148 
00154     operator DoubleList() const;
00155 
00163     operator long double() const;
00164 
00172     operator double() const;
00173 
00181     operator float() const;
00182 
00190     operator short int() const;
00191 
00199     operator unsigned short int() const;
00200 
00209     operator int() const;
00210 
00218     operator unsigned int() const;
00219 
00227     operator long int() const;
00228 
00236     operator unsigned long int() const;
00237 
00245     operator long long() const;
00246 
00254     operator unsigned long long() const;
00255 
00262     const char* toChar() const;
00264 
00267 
00268 
00270     DataValue& operator=(const char*);
00272     DataValue& operator=(const std::string&);
00274     DataValue& operator=(const String&);
00276     DataValue& operator=(const QString&);
00278     DataValue& operator=(const StringList&);
00280     DataValue& operator=(const IntList&);
00282     DataValue& operator=(const DoubleList&);
00284     DataValue& operator=(const long double);
00286     DataValue& operator=(const double);
00288     DataValue& operator=(const float);
00290     DataValue& operator=(const short int);
00292     DataValue& operator=(const unsigned short int);
00294     DataValue& operator=(const int);
00296     DataValue& operator=(const unsigned);
00298     DataValue& operator=(const long int);
00300     DataValue& operator=(const unsigned long);
00302     DataValue& operator=(const long long);
00304     DataValue& operator=(const unsigned long long);
00305 
00307 
00311 
00312 
00314     String toString() const;
00315 
00317     QString toQString() const;
00318 
00326     bool toBool() const;
00328 
00330     inline DataType valueType() const
00331     {
00332       return value_type_;
00333     }
00334 
00336     DataValue& operator=(const DataValue&);
00337 
00339     inline bool isEmpty() const
00340     {
00341       return value_type_ == EMPTY_VALUE;
00342     }
00343 
00346 
00347 
00349     inline bool hasUnit() const
00350     {
00351       return unit_ != "";
00352     }
00353 
00355     const String& getUnit() const;
00356 
00358     void setUnit(const String& unit);
00359 
00361 
00363     friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
00364 
00366     friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
00367 
00369     friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
00370 
00372     friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
00373 
00375     friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
00376 
00377 protected:
00378 
00380     DataType value_type_;
00381 
00383     union
00384     {
00385       SignedSize ssize_;
00386       DoubleReal dou_;
00387       String* str_;
00388       StringList* str_list_;
00389       IntList* int_list_;
00390       DoubleList* dou_list_;
00391     } data_;
00392 
00393 private:
00395     String unit_;
00396 
00398     void clear_();
00399   };
00400 }
00401 
00402 #endif // OPENMS_DATASTRUCTURES_DATAVALUE_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:38 using doxygen 1.7.1