1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef UDM_LUXENUM_HXX 25 #define UDM_LUXENUM_HXX 26 27 28 29 // USED SERVICES 30 // BASE CLASSES 31 // COMPONENTS 32 // PARAMETERS 33 #include <map> 34 #include <algorithm> 35 36 37 namespace lux 38 { 39 40 typedef std::map< intt, String > EnumValueMap; 41 42 43 template <class DIFF> 44 class Enum // : public Template_Base 45 { 46 public: 47 // TYPES 48 typedef Enum< DIFF > self; 49 50 // LIFECYCLE Enum(DIFF i_nValue,const char * i_sText)51 Enum( 52 DIFF i_nValue, 53 const char * i_sText ) 54 : nValue(i_nValue) { Values_()[nValue] = i_sText; 55 // Sequence_().insert( 56 // std::lower_bound( Sequence_().begin(), Sequence_().end(), i_nValue ), 57 // i_nValue ); 58 } Enum(DIFF i_nValue)59 Enum( 60 DIFF i_nValue ) 61 : nValue(i_nValue) { ; } Enum(intt i_nValue=0)62 Enum( 63 intt i_nValue = 0 ) 64 : nValue(i_nValue) { if ( NOT CheckIntt(i_nValue) ) { csv_assert(false); } } Enum(const self & i_rEnum)65 Enum( 66 const self & i_rEnum ) 67 : nValue(i_rEnum.nValue) {;} 68 operator =(DIFF i_nValue)69 self & operator=( 70 DIFF i_nValue ) 71 { nValue = i_nValue; return *this; } operator =(intt i_nValue)72 self & operator=( 73 intt i_nValue ) 74 { if ( CheckIntt(i_nValue) ) {nValue = DIFF(i_nValue);} 75 else {csv_assert(false);} return *this; } operator =(const self & i_rEnum)76 self & operator=( 77 const self & i_rEnum ) 78 { nValue = i_rEnum.nValue; return *this; } operator DIFF() const79 operator DIFF() const { return DIFF(nValue); } 80 operator ()() const81 DIFF operator()() const { return nValue; } Text() const82 const String & Text() const { return Values_()[nValue]; } 83 84 private: 85 static EnumValueMap & 86 Values_(); CheckIntt(intt i_nNumber)87 bool CheckIntt( 88 intt i_nNumber ) 89 { return Values_().find(i_nNumber) != Values_().end(); } 90 // DATA 91 intt nValue; 92 }; 93 94 95 96 97 } // namespace lux 98 #endif 99 100