3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
* Copyright (C) 2005 - 2010 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
28 |
|
|
29 |
namespace LinuxSampler { |
namespace LinuxSampler { |
30 |
|
|
31 |
|
/** |
32 |
|
* Base class of template class optional, not meant to be instantiated |
33 |
|
* directly. It just provides the optional<T>::nothing member. |
34 |
|
*/ |
35 |
class optional_base { |
class optional_base { |
36 |
public: |
public: |
37 |
class nothing_t { public: nothing_t() {} }; |
class nothing_t { public: nothing_t() {} }; |
39 |
static const nothing_t nothing; |
static const nothing_t nothing; |
40 |
}; |
}; |
41 |
|
|
42 |
|
/** |
43 |
|
* This class can be used for any variable that might not have a value |
44 |
|
* set. E.g. as a return value type of a function, since in the case of |
45 |
|
* return values of functions it's often difficult to return a pointer |
46 |
|
* variable which might do the trick of an optional return value. It |
47 |
|
* behaves pretty much like a pointer though. That is, it can be checked |
48 |
|
* against NULL and the actual value can be dereferenced with the |
49 |
|
* typical C pointer dereference operators. |
50 |
|
*/ |
51 |
template<class T> |
template<class T> |
52 |
class optional : public optional_base { |
class optional : public optional_base { |
53 |
public: |
public: |
80 |
return data; |
return data; |
81 |
} |
} |
82 |
|
|
83 |
optional& operator =(const optional& arg) throw (Exception) { |
optional& operator =(const optional& arg) { |
|
if (!arg.initialized) throw Exception("optional variable not initialized"); |
|
84 |
this->data = arg.data; |
this->data = arg.data; |
85 |
initialized = true; |
initialized = arg.initialized; |
86 |
return *this; |
return *this; |
87 |
} |
} |
88 |
|
|