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