Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
5.2 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_VALUE
  5. #define SIMC_VALUE
  6. /*
  7. * This file contains classes that model the various kinds of values that
  8. * can occur in a MIB module
  9. */
  10. /*
  11. * The base class for all the values. Just stores the line and column number
  12. */
  13. class SIMCValue
  14. {
  15. long _line, _column;
  16. // Used in mostly in the destructors of the derived classes
  17. BOOL _useReferenceCount;
  18. protected:
  19. SIMCValue( long line = 0, long column = 0)
  20. : _line(line), _column(column), _useReferenceCount(FALSE)
  21. {}
  22. public:
  23. virtual ~SIMCValue() {}
  24. friend ostream& operator<< ( ostream& outStream, const SIMCValue& obj)
  25. {
  26. obj.WriteValue(outStream);
  27. return outStream;
  28. }
  29. long GetLine() const
  30. {
  31. return _line;
  32. }
  33. void SetLine( long x)
  34. {
  35. _line = x;
  36. }
  37. long GetColumn() const
  38. {
  39. return _column;
  40. }
  41. void SetColumn( long x)
  42. {
  43. _column = x;
  44. }
  45. void SetUseReferenceCount(BOOL val)
  46. {
  47. _useReferenceCount = val;
  48. }
  49. BOOL UseReferenceCount() const
  50. {
  51. return _useReferenceCount;
  52. }
  53. virtual void WriteValue(ostream& outStream) const
  54. {
  55. outStream << "line(" << _line << "), column(" << _column << ")";
  56. }
  57. };
  58. /*
  59. * Value for the INTEGER type
  60. */
  61. class SIMCIntegerValue : public SIMCValue
  62. {
  63. long _val;
  64. /* A long value is used to store 32 bit unsigned, as well as signed
  65. * values. Hence this flag is required to indicate whether a minus sign
  66. * was present in front of this number in a MIB file. If this is false,
  67. * then the above long value should be treated as an unsigned value
  68. */
  69. BOOL _isUnsigned;
  70. public:
  71. SIMCIntegerValue ( long x, BOOL isUnsigned, long line = 0, long column = 0)
  72. : _val(x), _isUnsigned(isUnsigned), SIMCValue(line, column)
  73. {}
  74. long GetIntegerValue() const { return _val; }
  75. void SetIntegerValue(long x) { _val = x; }
  76. BOOL IsUnsigned() const
  77. {
  78. return _isUnsigned;
  79. }
  80. virtual void WriteValue( ostream& outStream) const
  81. {
  82. outStream << "Integer (" << _val << "), ";
  83. SIMCValue::WriteValue(outStream);
  84. outStream << endl;
  85. }
  86. virtual BOOL operator == (const SIMCIntegerValue& rhs) const
  87. {
  88. return _val == rhs._val;
  89. }
  90. };
  91. BOOL IsLessThan(long a, BOOL aUnsigned, long b, BOOL bUnsigned);
  92. /*
  93. * Value for the NULL type
  94. */
  95. class SIMCNullValue : public SIMCValue
  96. {
  97. public:
  98. SIMCNullValue ( long line = 0, long column = 0)
  99. : SIMCValue(line, column)
  100. {}
  101. virtual void WriteValue( ostream& outStream) const
  102. {
  103. outStream << "NULL value ";
  104. SIMCValue::WriteValue(outStream);
  105. outStream << endl;
  106. }
  107. virtual BOOL operator == (const SIMCIntegerValue& rhs) const
  108. {
  109. return TRUE;
  110. }
  111. };
  112. /*
  113. * Value for the BOOL type
  114. */
  115. class SIMCBooleanValue : public SIMCValue
  116. {
  117. BOOL _val;
  118. public:
  119. SIMCBooleanValue ( BOOL val, long line = 0, long column = 0 )
  120. : _val(val), SIMCValue(line, column)
  121. {}
  122. BOOL GetBooleanValue() const
  123. {
  124. return _val;
  125. }
  126. void SetBooleanValue(BOOL x)
  127. {
  128. _val = x;
  129. }
  130. virtual void WriteValue( ostream& outStream) const
  131. {
  132. outStream << "BOOLEAN VALUE (" << ((_val)? "TRUE" : "FALSE") <<
  133. ") ";
  134. SIMCValue::WriteValue(outStream);
  135. outStream << endl;
  136. }
  137. virtual BOOL operator == (const SIMCBooleanValue& rhs) const
  138. {
  139. if (_val)
  140. return rhs._val;
  141. else
  142. return !rhs._val;
  143. }
  144. };
  145. /*
  146. * value for the OCTET STRING type
  147. */
  148. class SIMCOctetStringValue : public SIMCValue
  149. {
  150. char * _val;
  151. BOOL _binary;
  152. public:
  153. SIMCOctetStringValue ( BOOL binary, char * x, long line = 0, long column = 0)
  154. : _binary(binary), SIMCValue(line, column)
  155. {
  156. _val = NewString(x);
  157. }
  158. virtual ~SIMCOctetStringValue()
  159. {
  160. if(_val)
  161. delete []_val;
  162. }
  163. BOOL IsBinary() const
  164. {
  165. return _binary;
  166. }
  167. const char *GetOctetStringValue() const { return _val; }
  168. void SetOctetStringValue(BOOL binary, char * x)
  169. {
  170. if(_val)
  171. delete _val;
  172. _val = NewString(x);
  173. _binary = binary;
  174. }
  175. virtual void WriteValue( ostream& outStream) const
  176. {
  177. outStream << "Octet String (" << _val << "), ";
  178. SIMCValue::WriteValue(outStream);
  179. outStream << endl;
  180. }
  181. virtual BOOL operator == (const SIMCOctetStringValue& rhs) const
  182. {
  183. return (_binary == rhs._binary) &&(strcmp(_val, rhs._val) == 0);
  184. }
  185. int GetNumberOfOctets() const
  186. {
  187. if(_val)
  188. {
  189. int l = strlen(_val);
  190. if(!_binary)
  191. return l/2 + ((l%2)?1:0);
  192. return l/4 + ((l%4)?1:0);
  193. }
  194. else
  195. return 0;
  196. }
  197. };
  198. class SIMCBitValue
  199. {
  200. public:
  201. CString _name;
  202. long _line, _column;
  203. SIMCBitValue(const CString& name, long line, long column)
  204. : _name(name), _line(line), _column(column)
  205. {}
  206. };
  207. typedef CList<SIMCBitValue *, SIMCBitValue*> SIMCBitValueList;
  208. class SIMCBitsValue : public SIMCValue
  209. {
  210. SIMCBitValueList *_valueList;
  211. public:
  212. SIMCBitsValue(SIMCBitValueList *valueList)
  213. {
  214. _valueList = valueList;
  215. }
  216. void AddValue( SIMCBitValue *value)
  217. {
  218. _valueList->AddTail(value);
  219. }
  220. const SIMCBitValueList * GetValueList() const
  221. {
  222. return _valueList;
  223. }
  224. };
  225. #endif // SIMC_VALUE