Source code of Windows XP (NT5)
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.

148 lines
3.1 KiB

  1. /*
  2. *
  3. * REFERENCES:
  4. *
  5. * NOTES:
  6. *
  7. * REVISIONS:
  8. * sja11Nov92: Added a new constructor which allows the use of #defines's
  9. * for the value parameter
  10. * ker20Nov92: Added extern "C" to string.h, removed redefinitions, added
  11. * SetValue function.
  12. * pcy02Dec92: Added #include err.h. We need it.
  13. * ane16Dec92: Added cdefine.h
  14. * ane08Feb93: Added copy constructor
  15. * cad07Oct93: Plugging Memory Leaks
  16. * cad27Dec93: include file madness
  17. * pcy13Apr94: Use automatic variables decrease dynamic mem allocation
  18. * mwh01Jun94: port for INTERACTIVE
  19. * mwh07Jun94: port for NCR
  20. * daf17May95: port for ALPHA/OS
  21. * djs02Oct95: port for AIX 4.1
  22. * ntf03Jan96: added printMeOut and operator<< functions for Attribute class
  23. *
  24. * v-stebe 29Jul2000 changed mem. alloc from new to on the heap (bug #46327)
  25. */
  26. #ifdef APCDEBUG
  27. #include <iostream.h>
  28. #endif
  29. #define INCL_BASE
  30. #define INCL_DOS
  31. #define INCL_NOPM
  32. #include "cdefine.h"
  33. extern "C" {
  34. #include <string.h>
  35. #if (C_OS & (C_INTERACTIVE | C_ALPHAOSF)) || ((C_OS & C_AIX) && (C_AIX_VERSION & C_AIX4))
  36. # include <stdlib.h>
  37. #else
  38. # include <malloc.h>
  39. #endif
  40. #include <stdio.h>
  41. }
  42. #include "attrib.h"
  43. #include "isa.h"
  44. #include "err.h"
  45. #if (C_OS & C_NCR)
  46. # include "incfix.h"
  47. #endif
  48. //-------------------------------------------------------------------
  49. Attribute::Attribute(INT aCode, PCHAR aValue)
  50. : theAttributeCode(aCode), theValue((CHAR*)NULL)
  51. {
  52. if (aValue)
  53. theValue = _strdup(aValue);
  54. }
  55. Attribute::Attribute(INT aCode, LONG aValue)
  56. : theAttributeCode(aCode)//, theValue(_strdup(aValue))
  57. {
  58. CHAR strvalue[32];
  59. sprintf(strvalue, "%ld", aValue);
  60. theValue = _strdup(strvalue);
  61. }
  62. Attribute::Attribute(const Attribute &anAttr)
  63. : theAttributeCode (anAttr.theAttributeCode)
  64. {
  65. if (anAttr.theValue)
  66. theValue = _strdup (anAttr.theValue);
  67. else
  68. theValue = (PCHAR)NULL;
  69. }
  70. INT Attribute::SetValue(LONG aValue)
  71. {
  72. CHAR the_temp_string[32];
  73. sprintf(the_temp_string, "%ld", aValue);
  74. return SetValue(the_temp_string);
  75. }
  76. INT Attribute::SetValue(const PCHAR aValue)
  77. {
  78. if (!aValue)
  79. return ErrNO_VALUE;
  80. if (theValue)
  81. {
  82. free(theValue);
  83. theValue = (CHAR*)NULL;
  84. }
  85. theValue=_strdup(aValue);
  86. return ErrNO_ERROR;
  87. }
  88. const PCHAR Attribute::GetValue()
  89. {
  90. return theValue;
  91. }
  92. VOID Attribute::SetCode(INT aCode) {
  93. theAttributeCode = aCode;
  94. }
  95. //-------------------------------------------------------------------
  96. Attribute::~Attribute()
  97. {
  98. if (theValue) {
  99. free(theValue);
  100. }
  101. }
  102. //-------------------------------------------------------------------
  103. INT Attribute::Equal(RObj anObject) const
  104. {
  105. if (anObject.IsA() != IsA())
  106. return FALSE;
  107. if ( ((RAttribute) anObject).GetCode() == theAttributeCode )
  108. // && ( !strcmp(theValue, ((RAttribute) anObject).GetValue()) ))
  109. return TRUE;
  110. return FALSE;
  111. }
  112. #ifdef APCDEBUG
  113. ostream & operator<< (ostream& os, Attribute & obj) {
  114. return(obj.printMeOut(os));
  115. }
  116. ostream& Attribute::printMeOut(ostream& os)
  117. {
  118. os << theValue << "(" << theAttributeCode << ")" << endl;
  119. return os;
  120. }
  121. #endif