1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef UDM_LUXENUM_HXX 29 #define UDM_LUXENUM_HXX 30 31 32 33 // USED SERVICES 34 // BASE CLASSES 35 // COMPONENTS 36 // PARAMETERS 37 #include <map> 38 #include <algorithm> 39 40 41 namespace lux 42 { 43 44 typedef std::map< intt, String > EnumValueMap; 45 46 47 template <class DIFF> 48 class Enum // : public Template_Base 49 { 50 public: 51 // TYPES 52 typedef Enum< DIFF > self; 53 54 // LIFECYCLE 55 Enum( 56 DIFF i_nValue, 57 const char * i_sText ) 58 : nValue(i_nValue) { Values_()[nValue] = i_sText; 59 // Sequence_().insert( 60 // std::lower_bound( Sequence_().begin(), Sequence_().end(), i_nValue ), 61 // i_nValue ); 62 } 63 Enum( 64 DIFF i_nValue ) 65 : nValue(i_nValue) { ; } 66 Enum( 67 intt i_nValue = 0 ) 68 : nValue(i_nValue) { if ( NOT CheckIntt(i_nValue) ) { csv_assert(false); } } 69 Enum( 70 const self & i_rEnum ) 71 : nValue(i_rEnum.nValue) {;} 72 73 self & operator=( 74 DIFF i_nValue ) 75 { nValue = i_nValue; return *this; } 76 self & operator=( 77 intt i_nValue ) 78 { if ( CheckIntt(i_nValue) ) {nValue = DIFF(i_nValue);} 79 else {csv_assert(false);} return *this; } 80 self & operator=( 81 const self & i_rEnum ) 82 { nValue = i_rEnum.nValue; return *this; } 83 operator DIFF() const { return DIFF(nValue); } 84 85 DIFF operator()() const { return nValue; } 86 const String & Text() const { return Values_()[nValue]; } 87 88 private: 89 static EnumValueMap & 90 Values_(); 91 bool CheckIntt( 92 intt i_nNumber ) 93 { return Values_().find(i_nNumber) != Values_().end(); } 94 // DATA 95 intt nValue; 96 }; 97 98 99 100 101 } // namespace lux 102 #endif 103 104