autoNumber.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: autoNumber.h /main/6 1996/10/08 19:24:51 cde-hal $ */
  24. #ifndef _autoNumber_h
  25. #define _autoNumber_h 1
  26. #ifndef CDE_NEXT
  27. #else
  28. #include "dti_cc/CC_Slist.h"
  29. #include "dti_cc/CC_Stack.h"
  30. #endif
  31. #include "utility/buffer.h"
  32. #include "FPExceptions.h"
  33. class autoNumber : public Destructable
  34. {
  35. public:
  36. enum autoNumberType { NUMERIC, ALPHABETIC, ROMAN };
  37. autoNumber(const char* nm, enum autoNumberType, int delta, const char* prefix, const char* postfix);
  38. virtual ~autoNumber();
  39. void setNumTagsSeen();
  40. virtual const char* getValue() = 0;
  41. virtual void setNextValue() = 0;
  42. virtual void reset();
  43. void push();
  44. void pop();
  45. unsigned int operator==(const autoNumber&);
  46. friend ostream& operator<<(ostream&, const autoNumber&) ;
  47. protected:
  48. static buffer f_buf;
  49. char* f_name;
  50. enum autoNumberType f_type;
  51. int f_delta;
  52. char* f_prefix;
  53. char* f_postfix;
  54. int f_initialValue;
  55. Stack<int> f_values;
  56. Stack<int> f_serial_nums;
  57. };
  58. class autoNumberNumeric : public autoNumber
  59. {
  60. public:
  61. autoNumberNumeric (const char* name, int delta, int initialValue, const char* prefix, const char* postfix);
  62. ~autoNumberNumeric();
  63. void setNextValue() ;
  64. const char* getValue() ;
  65. };
  66. class autoNumberCased : public autoNumber
  67. {
  68. public:
  69. enum CaseType { UPPER, LOWER};
  70. autoNumberCased(const char* name,
  71. enum autoNumberType,
  72. int delta,
  73. CaseType,
  74. const char* prefix,
  75. const char* postfix
  76. );
  77. ~autoNumberCased();
  78. protected:
  79. CaseType f_case;
  80. };
  81. //////////////////////////////////////////////////////
  82. // Sequence example:
  83. // a, b, ..., z,
  84. // aa, ab, az,
  85. // ba, bb, bz,
  86. // ... ...
  87. //////////////////////////////////////////////////////
  88. class autoNumberAlphabetic : public autoNumberCased
  89. {
  90. private:
  91. static const int f_base;
  92. static char f_lowerCaseLetters[26];
  93. static char f_upperCaseLetters[26];
  94. public:
  95. autoNumberAlphabetic
  96. (const char* name,
  97. int delta,
  98. CaseType,
  99. const char* initialValue,
  100. const char* prefix,
  101. const char* postfix
  102. );
  103. ~autoNumberAlphabetic();
  104. void setNextValue() ;
  105. const char* getValue() ;
  106. // convert an integer to an alphabetic autonumber
  107. // Example
  108. // a <- 0, b <- 1, ..., z <- 25
  109. // aa <- 26, ab <- 27, ..., az <- 51
  110. static const char* intToAlpha(int, enum CaseType);
  111. // convert an alphabetic autonumber to an integer
  112. // Example
  113. // a -> 0, b -> 1, ..., z -> 25
  114. // aa -> 26, ab -> 27, ..., az -> 51
  115. static int alphaToInt(const char*, enum CaseType);
  116. };
  117. class autoNumberRoman : public autoNumberCased
  118. {
  119. private:
  120. static char RomanNumberBuf[256];
  121. private:
  122. static int getDigit(const char*&);
  123. public:
  124. autoNumberRoman
  125. (const char* name,
  126. int delta,
  127. CaseType,
  128. const char* initialValue,
  129. const char* prefix,
  130. const char* postfix
  131. );
  132. ~autoNumberRoman();
  133. void setNextValue() ;
  134. const char* getValue() ;
  135. static int RomanToArabic(const char*);
  136. // ArabicToRoman needs to be non-static because of the requirement of
  137. // case sensitiveness
  138. const char* ArabicToRoman(int);
  139. };
  140. #ifndef CDE_NEXT
  141. class autoNumberListT : public CC_TPtrSlist<autoNumber>
  142. #else
  143. class autoNumberListT : public CC_TPtrSlist<autoNumber>
  144. #endif
  145. {
  146. public:
  147. autoNumberListT() {};
  148. virtual ~autoNumberListT() {};
  149. unsigned int operator==(const autoNumberListT&);
  150. } ;
  151. #endif