/usr/include/OpenMS/DATASTRUCTURES/DataValue.h is in libopenms-dev 1.11.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | // --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Stephan Aiche$
// $Authors: Marc Sturm $
// --------------------------------------------------------------------------
#ifndef OPENMS_DATASTRUCTURES_DATAVALUE_H
#define OPENMS_DATASTRUCTURES_DATAVALUE_H
#include <OpenMS/CONCEPT/Exception.h>
#include <OpenMS/DATASTRUCTURES/String.h>
#include <OpenMS/DATASTRUCTURES/StringList.h>
#include <OpenMS/DATASTRUCTURES/IntList.h>
#include <OpenMS/DATASTRUCTURES/DoubleList.h>
#include <QtCore/QString>
namespace OpenMS
{
/**
@brief Class to hold strings, numeric values, lists of strings and lists of numeric values.
- To choose one of these types, just use the appropriate constructor.
- Automatic conversion is supported and throws Exceptions in case of invalid conversions.
- An empty object is created with the default constructor.
@ingroup Datastructures
*/
class OPENMS_DLLAPI DataValue
{
public:
/// Empty data value for comparisons
static const DataValue EMPTY;
/// Supported types for DataValue
enum DataType
{
STRING_VALUE, ///< string value
INT_VALUE, ///< integer value
DOUBLE_VALUE, ///< double value
STRING_LIST, ///< string list
INT_LIST, ///< integer list
DOUBLE_LIST, ///< double list
EMPTY_VALUE ///< empty value
};
/// @name Constructors and destructors
//@{
/// default constructor
DataValue();
/// specific constructor for char* (converted to string)
DataValue(const char*);
/// specific constructor for std::string values
DataValue(const std::string&);
/// specific constructor for string values
DataValue(const String&);
/// specific constructor for QString values
DataValue(const QString&);
/// specific constructor for string lists
DataValue(const StringList&);
/// specific constructor for integer lists
DataValue(const IntList&);
/// specific constructor for double lists
DataValue(const DoubleList&);
/// specific constructor for long double values (note: the implementation uses DoubleReal)
DataValue(long double);
/// specific constructor for double values (note: the implementation uses DoubleReal)
DataValue(double);
/// specific constructor for float values (note: the implementation uses DoubleReal)
DataValue(float);
/// specific constructor for short int values (note: the implementation uses SignedSize)
DataValue(short int);
/// specific constructor for unsigned short int values (note: the implementation uses SignedSize)
DataValue(unsigned short int);
/// specific constructor for int values (note: the implementation uses SignedSize)
DataValue(int);
/// specific constructor for unsigned int values (note: the implementation uses SignedSize)
DataValue(unsigned);
/// specific constructor for long int values (note: the implementation uses SignedSize)
DataValue(long int);
/// specific constructor for unsigned long int values (note: the implementation uses SignedSize)
DataValue(unsigned long);
/// specific constructor for long long int values (note: the implementation uses SignedSize)
DataValue(long long);
/// specific constructor for unsigned long long int values (note: the implementation uses SignedSize)
DataValue(unsigned long long);
/// copy constructor
DataValue(const DataValue&);
/// destructor
virtual ~DataValue();
//@}
///@name cast operators
///These methods are used when the DataType is known.
///If they are applied to a DataValue with the wrong DataType, an exception is thrown.
//@{
/**
@brief conversion operator to string
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator std::string() const;
/**
@brief conversion operator to string list
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator StringList() const;
/**
@brief conversion operator to integer list
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator IntList() const;
/**
@brief conversion operator to double list
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator DoubleList() const;
/**
@brief conversion operator to long double
Note: The implementation uses typedef DoubleReal (as opposed to float, double, long double.)
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator long double() const;
/**
@brief conversion operator to double
Note: The implementation uses typedef DoubleReal (as opposed to float, double, long double.)
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator double() const;
/**
@brief conversion operator to float
Note: The implementation uses typedef DoubleReal (as opposed to float, double, long double.)
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator float() const;
/**
@brief conversion operator to short int
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator short int() const;
/**
@brief conversion operator to unsigned short int
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator unsigned short int() const;
/**
@brief conversion operator to int
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator int() const;
/**
@brief conversion operator to unsigned int
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator unsigned int() const;
/**
@brief conversion operator to long int
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator long int() const;
/**
@brief conversion operator to unsigned long int
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator unsigned long int() const;
/**
@brief conversion operator to long long
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator long long() const;
/**
@brief conversion operator to unsigned long long
Note: The implementation uses typedef SignedSize.
@exception Exception::ConversionError is thrown if a cast from the the wrong type is requested
*/
operator unsigned long long() const;
/**
@brief Convert DataValues to char*
If the DataValue contains a string, a pointer to it's char* is returned.
If the DataValue is empty, NULL is returned.
*/
const char* toChar() const;
//@}
///@name assignment/conversion operators
///These methods are used to assign supported types to DataType.
//@{
/// specific assignment for char* (converted to string)
DataValue& operator=(const char*);
/// specific assignment for std::string values
DataValue& operator=(const std::string&);
/// specific assignment for string values
DataValue& operator=(const String&);
/// specific assignment for QString values
DataValue& operator=(const QString&);
/// specific assignment for string lists
DataValue& operator=(const StringList&);
/// specific assignment for integer lists
DataValue& operator=(const IntList&);
/// specific assignment for double lists
DataValue& operator=(const DoubleList&);
/// specific assignment for long double values (note: the implementation uses DoubleReal)
DataValue& operator=(const long double);
/// specific assignment for double values (note: the implementation uses DoubleReal)
DataValue& operator=(const double);
/// specific assignment for float values (note: the implementation uses DoubleReal)
DataValue& operator=(const float);
/// specific assignment for short int values (note: the implementation uses SignedSize)
DataValue& operator=(const short int);
/// specific assignment for unsigned short int values (note: the implementation uses SignedSize)
DataValue& operator=(const unsigned short int);
/// specific assignment for int values (note: the implementation uses SignedSize)
DataValue& operator=(const int);
/// specific assignment for unsigned int values (note: the implementation uses SignedSize)
DataValue& operator=(const unsigned);
/// specific assignment for long int values (note: the implementation uses SignedSize)
DataValue& operator=(const long int);
/// specific assignment for unsigned long int values (note: the implementation uses SignedSize)
DataValue& operator=(const unsigned long);
/// specific assignment for long long int values (note: the implementation uses SignedSize)
DataValue& operator=(const long long);
/// specific assignment for unsigned long long int values (note: the implementation uses SignedSize)
DataValue& operator=(const unsigned long long);
//@}
///@name conversion operators
///These methods can be used independent of the DataType. If you already know the DataType, you should use a cast operator!
/// <BR>For conversion of string DataValues to numeric types, first use toString() and then the conversion methods of String.
//@{
///Conversion to String.
String toString() const;
///Conversion to QString
QString toQString() const;
/**
@brief Conversion to bool
Converts the strings 'true' and 'false' to a bool.
@exception Exception::ConversionError is thrown for non-string parameters and string parameters with values other than 'true' and 'false'.
*/
bool toBool() const;
//@}
/// returns the type of value stored
inline DataType valueType() const
{
return value_type_;
}
/// assignment operator
DataValue& operator=(const DataValue&);
/// test if the value is empty
inline bool isEmpty() const
{
return value_type_ == EMPTY_VALUE;
}
///@name Methods to handle units
///These methods are used when the DataValue has an associated unit.
//@{
/// Check if the value has a unit
inline bool hasUnit() const
{
return unit_ != "";
}
/// Return the unit associated to this DataValue.
const String& getUnit() const;
/// Sets the unit to the given String.
void setUnit(const String& unit);
//@}
/// output stream operator
friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
/// Equality comparator
friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
/// Smaller than comparator (for lists we use the size)
friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
/// Greater than comparator (for lists we use the size)
friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
/// Equality comparator
friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
protected:
/// Type of the currently stored value
DataType value_type_;
/// Space to store the data
union
{
SignedSize ssize_;
DoubleReal dou_;
String* str_;
StringList* str_list_;
IntList* int_list_;
DoubleList* dou_list_;
} data_;
private:
/// The unit of the data value (if it has one), otherwise empty string.
String unit_;
/// Clears the current state of the DataValue and release every used memory.
void clear_();
};
}
#endif // OPENMS_DATASTRUCTURES_DATAVALUE_H
|