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.

173 lines
4.1 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_OID_VALUE
  5. #define SIMC_OID_VALUE
  6. /*
  7. * This file contains classes for modelling OID values
  8. * OID values are of 2 types, for purposes of the compiler
  9. * A clean oid value, is one in which the values of the individual components
  10. * are known presently. Hence a list of integers is all that is required to model
  11. * it, as is done by the SIMCCleanOidValue typedef. It is referred to, as a
  12. * "clean" oid value, in the documentation.
  13. * However, while compiling a MIB, we might not know the values of
  14. * of all the components of an OID (these may be symbols that refer
  15. * to integer values, or to other oid values. Hence, we need to model this
  16. * too, as is done by the SIMCOidValue class. It is often referred to as
  17. * an "unclean" OID value in the documentation.
  18. */
  19. // Each component of the SIMCOidValue Object. This is basically a
  20. // pointer to SIMCSymbol*, with other associated information.
  21. class SIMCOidComponent
  22. {
  23. char *_name;
  24. long _nameLine, _nameColumn;
  25. // The symbol that represents this component.
  26. // It should resolve to an integer, or another oid value
  27. SIMCSymbol **_value;
  28. long _valueLine, _valueColumn;
  29. public:
  30. SIMCOidComponent(SIMCSymbol **value, long valueLine, long valueColumn,
  31. char *name, long nameLine, long nameColumn)
  32. : _value(value), _valueLine(valueLine), _valueColumn(valueColumn),
  33. _nameLine(nameLine), _nameColumn(nameColumn)
  34. {
  35. if(name)
  36. _name = NewString(name);
  37. else
  38. _name = NULL;
  39. }
  40. virtual ~SIMCOidComponent()
  41. {
  42. if(_name)
  43. delete []_name;
  44. }
  45. SIMCSymbol ** GetValue() const
  46. {
  47. return _value;
  48. }
  49. long GetNameLine() const
  50. {
  51. return _nameLine;
  52. }
  53. void SetNameLine(long x)
  54. {
  55. _nameLine = x;
  56. }
  57. long GetNameColumn() const
  58. {
  59. return _nameColumn;
  60. }
  61. void SetNameColumn(long x)
  62. {
  63. _nameColumn = x;
  64. }
  65. long GetValueLine() const
  66. {
  67. return _valueLine;
  68. }
  69. void SetValueLine(long x)
  70. {
  71. _valueLine = x;
  72. }
  73. long GetValueColumn() const
  74. {
  75. return _valueColumn;
  76. }
  77. void SetValueColumn(long x)
  78. {
  79. _valueColumn = x;
  80. }
  81. friend ostream& operator << ( ostream& outStream, const SIMCOidComponent& obj);
  82. };
  83. typedef CList<SIMCOidComponent *, SIMCOidComponent*> SIMCOidComponentList;
  84. // An "unclean" oid value
  85. class SIMCOidValue : public SIMCValue
  86. {
  87. SIMCOidComponentList * _listOfComponents;
  88. public:
  89. SIMCOidValue( SIMCOidComponentList* listOfComponents,
  90. long line = 0, long column = 0)
  91. : _listOfComponents(listOfComponents),
  92. SIMCValue(line, column)
  93. {
  94. if(_listOfComponents)
  95. {
  96. SIMCOidComponent *next;
  97. POSITION p = _listOfComponents->GetHeadPosition();
  98. while(p)
  99. {
  100. next = _listOfComponents->GetNext(p);
  101. (*next->GetValue())->IncrementReferenceCount();
  102. }
  103. }
  104. }
  105. ~SIMCOidValue()
  106. {
  107. if(_listOfComponents)
  108. {
  109. SIMCOidComponent *next;
  110. BOOL useReferenceCount = UseReferenceCount();
  111. while(!_listOfComponents->IsEmpty())
  112. {
  113. next = _listOfComponents->RemoveHead();
  114. if(useReferenceCount)
  115. (*next->GetValue())->DecrementReferenceCount();
  116. delete next;
  117. }
  118. delete _listOfComponents;
  119. }
  120. }
  121. void SetListOfComponents(SIMCOidComponentList *list)
  122. {
  123. _listOfComponents = list;
  124. }
  125. SIMCOidComponentList *GetListOfComponents() const
  126. {
  127. return _listOfComponents;
  128. }
  129. virtual void WriteValue( ostream& outStream) const;
  130. };
  131. /*
  132. * A "clean" oid value
  133. */
  134. typedef CList<int, int> SIMCCleanOidValue;
  135. // Functions to operate on a clean OID value
  136. ostream& operator << (ostream& outStream, const SIMCCleanOidValue& obj);
  137. operator == (const SIMCCleanOidValue & lhs, const SIMCCleanOidValue & rhs);
  138. operator < (const SIMCCleanOidValue & lhs, const SIMCCleanOidValue & rhs);
  139. void AppendOid(SIMCCleanOidValue& to, const SIMCCleanOidValue& from);
  140. char * CleanOidValueToString(const SIMCCleanOidValue& value);
  141. SIMCCleanOidValue& CleanOidValueCopy(SIMCCleanOidValue & lhs, const SIMCCleanOidValue & rhs);
  142. #endif