Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNAttr.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_ATTR_H 00025 #define MN_ATTR_H 00026 00027 #include <config.h> 00028 00029 #include "mnstream.h" 00030 00031 #include "dictionary.h" 00032 00033 class AttrBase; 00034 00035 /**********************************************************************/ 00036 /* AttributeStore */ 00037 /**********************************************************************/ 00038 00039 class AttributeStore 00040 { 00041 dictionary<int,void*> _attribute_store; 00042 00043 public: 00054 void register_attribute( int idx, void* attr ); 00055 00056 /* Set function for all attributes. 00057 * <BR> 00058 * Since constructors for stream handlers should always have 00059 * identical calling conventions, parameters that concern only 00060 * a single stream handler must be managed differently. The 00061 * specific solution is the use of set functions. They specify 00062 * an attribute that can be private to the stream handler. If 00063 * it is an unknown attribute, it is silently ignored. 00064 * These parameters are stored by the stream handler and used 00065 * in the init function for initializing internal data structures 00066 * @note attribute 00067 * A value indicating the modified attribute to the 00068 * stream handler. 00069 * @param value 00070 * The new value. 00071 * @return True if the set function was evaluated, false if it 00072 * was not evaluated by the stream handler or any parent 00073 * class. 00074 * @warning These set functions are very dangerous. Since the xlC 3.1.4 00075 * does not support ANSI C++, it is impossible to make these 00076 * templates typesafe. The typecast to an Attr<ValueType> that 00077 * is used within this set function is not protected. The 00078 * caller must take care of his types. 00079 */ 00080 // template <unsigned int Index, class ValueType> 00081 // int set( const ValueType& value ); 00082 00083 void* get_attribute( int idx ); 00084 00085 template <class A> bool set( const A& value ) 00086 { 00087 void* item = get_attribute( A::Value ); 00088 if( item == NULL ) 00089 { 00090 return false; 00091 } 00092 00093 A* attr = (A*)item; 00094 return attr->set( value ); 00095 } 00096 }; 00097 00098 /**********************************************************************/ 00099 /* Attr<ValueType> */ 00100 /**********************************************************************/ 00101 00111 template <unsigned int Index, class ValueType> class Attr 00112 { 00113 public: 00114 enum { Value = Index }; 00115 00116 private: 00117 bool _set; 00118 ValueType _val; 00119 00121 Attr( const Attr& ); 00122 00124 Attr& operator=( const Attr& ); 00125 00126 protected: 00128 friend class AttributeStore; 00129 00134 public: 00135 explicit Attr( const ValueType& v ) 00136 : _set(false) 00137 , _val(v) 00138 { } 00139 00140 public: 00144 Attr( AttributeStore* valueStore ) 00145 : _set(false) 00146 { 00147 valueStore->register_attribute( Index, this ); 00148 } 00149 00150 virtual ~Attr( ) 00151 { } 00152 00154 bool set( const ValueType& v ) { 00155 if ( _set ) return false; 00156 _set = true; 00157 _val = v; 00158 return true; 00159 } 00160 00161 bool set( const Attr& v ) { 00162 if( _set ) return false; 00163 _set = true; 00164 _val = v._val; 00165 return true; 00166 } 00167 00171 operator ValueType() const { 00172 return _val; 00173 } 00174 00179 Attr& operator=( const ValueType& newval ) { 00180 _val = newval; 00181 return *this; 00182 } 00183 00184 ValueType& operator->() { 00185 return _val; 00186 } 00187 00188 bool isSet( ) const { 00189 return _set; 00190 } 00191 }; 00192 00193 template <class T, class U> struct Typelist 00194 { 00195 typedef T Head; 00196 typedef U Tail; 00197 }; 00198 00199 template <class TList, unsigned int index> struct TypeAt; 00200 00201 template <class Head, class Tail> 00202 struct TypeAt<Typelist<Head, Tail>, 0> 00203 { 00204 typedef Head Result; 00205 }; 00206 00207 template <class Head, class Tail, unsigned int i> 00208 struct TypeAt<Typelist<Head, Tail>, i> 00209 { 00210 typedef typename TypeAt<Tail,i-1>::Result Result; 00211 }; 00212 00213 #endif /* MN_ATTR_H */ 00214

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8