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.

208 lines
6.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: gmprop.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // gmprop.h: Graphical model property and property type declarations
  12. //
  13. #ifndef _GMPROP_H_
  14. #define _GMPROP_H_
  15. /*
  16. A word about DYNAMICALLY EXTENSIBLE OBJECTS and their usage.
  17. These graphical model object classes are designed to require only very occasional
  18. addition of new variables. Most add-on algorithms and functionality do, of course,
  19. require new variables, but there are several ways of meeting that need.
  20. 1) The standard C++ method of subclassing. This is a reasonable approach for
  21. some objects, but typically not for nodes in a belief network. Cascaded types
  22. nodes render header files unreadable and cause severe memory bloat. Also, most
  23. variables apply to a phase of processing or only certain nodes. These cases
  24. are better handled by the subsequence approaches.
  25. 2) Dynamic property lists. Every node in a belief network, as well as the network
  26. itself, has a property list. New GOBJPROPTYPEs can be easily created, then new PROPMBNs
  27. can be added to the appropriate nodes.
  28. 3) Dynamic bit flags. Every node and the network has a VFLAG vector, and member functions
  29. of the MPSYMTBL symbol table support conversion of names to indicies.
  30. 4) New edge types. An "edge" is a real C++ object, and the need for seriously complex
  31. and versatile data types can be met by creating a new edge type which connects
  32. pairs of other data structures. Edges can even be created which connect a node
  33. to itself, thus creating an "add-on" data structure.
  34. */
  35. #include <list>
  36. #include "basics.h"
  37. #include "symtmbn.h"
  38. #include "enumstd.h"
  39. class MODEL;
  40. class MBNET;
  41. ////////////////////////////////////////////////////////////////////
  42. // class GOBJPROPTYPE:
  43. // A named property type descriptor living in a belief network.
  44. // The word "choice" connotes an enumerated value (i.e., and
  45. // an integer property where each value from zero on is named).
  46. ////////////////////////////////////////////////////////////////////
  47. class GOBJPROPTYPE : public GOBJMBN
  48. {
  49. friend class DSCPARSER; // So the parser can create them
  50. friend class BNREG; // So they can be loaded from the Registry
  51. public:
  52. GOBJPROPTYPE () {}
  53. virtual ~ GOBJPROPTYPE() {}
  54. // Return object type
  55. virtual INT EType () const
  56. { return EBNO_PROP_TYPE ; }
  57. virtual GOBJMBN * CloneNew ( MODEL & modelSelf,
  58. MODEL & modelNew,
  59. GOBJMBN * pgobjNew = NULL );
  60. // Return property type descriptor
  61. UINT FPropType() const
  62. { return _fType; }
  63. // Return the list of enumerated choices
  64. const VZSREF VzsrChoice() const
  65. { return _vzsrChoice; }
  66. const ZSREF ZsrComment () const
  67. { return _zsrComment; }
  68. protected:
  69. UINT _fType; // Property type flags
  70. VZSREF _vzsrChoice; // Array of choice names
  71. ZSREF _zsrComment; // Comment
  72. HIDE_UNSAFE(GOBJPROPTYPE);
  73. };
  74. ////////////////////////////////////////////////////////////////////
  75. // class PROPMBN:
  76. // A property item definition living in a GNODEMBN
  77. ////////////////////////////////////////////////////////////////////
  78. class PROPMBN
  79. {
  80. friend class LTBNPROP; // for cloning
  81. public:
  82. PROPMBN ();
  83. PROPMBN ( const PROPMBN & bnp );
  84. PROPMBN & operator = ( const PROPMBN & bnp );
  85. // declare standard operators ==, !=, <, >
  86. DECLARE_ORDERING_OPERATORS(PROPMBN);
  87. bool operator == ( ZSREF zsrProp ) const;
  88. bool operator == ( SZC szcProp ) const;
  89. void Init ( GOBJPROPTYPE & bnpt );
  90. UINT Count () const;
  91. UINT FPropType () const
  92. { return _fType; }
  93. ZSREF ZsrPropType () const
  94. { return _zsrPropType; }
  95. ZSREF Zsr ( UINT i = 0 ) const;
  96. REAL Real ( UINT i = 0 ) const;
  97. void Reset ();
  98. void Set ( ZSREF zsr );
  99. void Set ( REAL r );
  100. void Add ( ZSREF zsr );
  101. void Add ( REAL r );
  102. protected:
  103. UINT _fType; // Property type flags
  104. ZSREF _zsrPropType; // Property name
  105. VZSREF _vzsrStrings; // Array of strings
  106. VREAL _vrValues; // Array of reals (or integers or choices)
  107. };
  108. ////////////////////////////////////////////////////////////////////
  109. // class LTBNPROP:
  110. // A list of properties
  111. ////////////////////////////////////////////////////////////////////
  112. class LTBNPROP : public list<PROPMBN>
  113. {
  114. public:
  115. // Find an element
  116. PROPMBN * PFind ( ZSREF zsrProp );
  117. const PROPMBN * PFind ( ZSREF zsrProp ) const;
  118. // Update or add and element; return true if element was already present
  119. bool Update ( const PROPMBN & bnp );
  120. // Force the list to contain only unique elements
  121. bool Uniqify ();
  122. // Clone from another list with another symbol table
  123. void Clone ( MODEL & model, const MODEL & modelOther, const LTBNPROP & ltbnOther );
  124. };
  125. ////////////////////////////////////////////////////////////////////
  126. // class PROPMGR:
  127. // Facilitates translation between user declarations of standard
  128. // properties and internal usage.
  129. //
  130. // N.B.: Remember that all ZSREFs are symbiotic to the MODEL of
  131. // origin and are therefore useless in other networks.
  132. ////////////////////////////////////////////////////////////////////
  133. class MODEL; // A belief network
  134. class GNODEMBN; // A node in a belief network
  135. class PROPMGR
  136. {
  137. public:
  138. PROPMGR ( MODEL & model );
  139. // Return a pointer to the requested standard property type
  140. GOBJPROPTYPE * PPropType ( ESTDPROP evp );
  141. // Return the name of the standard property
  142. ZSREF ZsrPropType ( ESTDPROP evp );
  143. // Return the user-defined value of the standard label or -1 if not defined
  144. int ILblToUser ( ESTDLBL elbl )
  145. {
  146. ASSERT_THROW( elbl < ESTDLBL_max, EC_INTERNAL_ERROR, "invalid standard label index" );
  147. return _vLblToUser[elbl];
  148. }
  149. // Return the standard label for the user-defined label value or -1
  150. int IUserToLbl ( int iLbl )
  151. {
  152. return iLbl >= 0 && iLbl < _vUserToLbl.size()
  153. ? _vUserToLbl[iLbl]
  154. : -1 ;
  155. }
  156. // Find a standard property in a property list
  157. PROPMBN * PFind ( LTBNPROP & ltprop, ESTDPROP estd );
  158. // Find a standard property in a node's property list
  159. PROPMBN * PFind ( GNODEMBN & gnd, ESTDPROP estd );
  160. // Find a standard property in the associated model's property list
  161. PROPMBN * PFind ( ESTDPROP estd );
  162. // Return a displayable name for a standard label
  163. static SZC SzcLbl ( int iLbl );
  164. protected:
  165. // The model we're referring to
  166. MODEL & _model;
  167. // Pointers to property types for currently used VOI types
  168. GOBJPROPTYPE * _vPropMap [ ESTDP_max ];
  169. // Map from predefined label index to user label index
  170. int _vLblToUser [ ESTDLBL_max ];
  171. // Map from user label index to predefined label index
  172. VINT _vUserToLbl;
  173. // Array of ZSREFs as recorded in the network used during construction
  174. VZSREF _vzsrPropType;
  175. HIDE_UNSAFE(PROPMGR);
  176. };
  177. #endif // _GMPROP_H_