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.

361 lines
8.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1998
  6. //
  7. // File: propmbn.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // PROPMBN.CPP
  12. //
  13. #include <basetsd.h>
  14. #include <assert.h>
  15. #include <string.h>
  16. #include "gmprop.h"
  17. #include "gmobj.h"
  18. #include "algos.h"
  19. GOBJMBN * GOBJPROPTYPE :: CloneNew (
  20. MODEL & modelSelf,
  21. MODEL & modelNew,
  22. GOBJMBN * pgobjNew )
  23. {
  24. GOBJPROPTYPE * pgproptype;
  25. if ( pgobjNew )
  26. {
  27. DynCastThrow( pgobjNew, pgproptype );
  28. }
  29. else
  30. {
  31. pgproptype = new GOBJPROPTYPE;
  32. }
  33. ASSERT_THROW( GOBJMBN::CloneNew( modelSelf, modelNew, pgproptype ),
  34. EC_INTERNAL_ERROR,
  35. "cloning failed to returned object pointer" );
  36. pgproptype->_fType = _fType;
  37. pgproptype->_zsrComment = modelNew.Mpsymtbl().intern( _zsrComment );
  38. modelNew.Mpsymtbl().CloneVzsref( modelSelf.Mpsymtbl(),
  39. _vzsrChoice,
  40. pgproptype->_vzsrChoice );
  41. return pgproptype;
  42. }
  43. PROPMBN :: PROPMBN ()
  44. :_fType(0)
  45. {
  46. }
  47. PROPMBN :: PROPMBN ( const PROPMBN & bnp )
  48. {
  49. self = bnp;
  50. }
  51. PROPMBN & PROPMBN :: operator = ( const PROPMBN & bnp )
  52. {
  53. _zsrPropType = bnp._zsrPropType;
  54. _fType = bnp._fType;
  55. _vzsrStrings = bnp._vzsrStrings;
  56. _vrValues = bnp._vrValues;
  57. return self;
  58. }
  59. void PROPMBN :: Init ( GOBJPROPTYPE & bnpt )
  60. {
  61. _zsrPropType = bnpt.ZsrefName();
  62. _fType = bnpt.FPropType();
  63. }
  64. bool PROPMBN :: operator == ( const PROPMBN & bnp ) const
  65. {
  66. return _zsrPropType == bnp._zsrPropType;
  67. }
  68. bool PROPMBN :: operator < ( const PROPMBN & bnp ) const
  69. {
  70. return _zsrPropType < bnp._zsrPropType;
  71. }
  72. bool PROPMBN :: operator == ( ZSREF zsrProp ) const
  73. {
  74. return ZsrPropType() == zsrProp;
  75. }
  76. bool PROPMBN :: operator == ( SZC szcProp ) const
  77. {
  78. return ::strcmp( szcProp, ZsrPropType().Szc() ) == 0;
  79. }
  80. UINT PROPMBN :: Count () const
  81. {
  82. if ( _fType & fPropString )
  83. return _vzsrStrings.size();
  84. else
  85. return _vrValues.size();
  86. }
  87. ZSREF PROPMBN :: Zsr ( UINT i ) const
  88. {
  89. if ( ((_fType & fPropArray) == 0 && i > 0)
  90. || (_fType & fPropString) == 0)
  91. throw GMException(EC_PROP_MISUSE,"not a string property or not an array");
  92. if ( i >= _vzsrStrings.size() )
  93. throw GMException(EC_PROP_MISUSE,"property index out of range");
  94. return _vzsrStrings[i];
  95. }
  96. REAL PROPMBN :: Real ( UINT i ) const
  97. {
  98. if ( ((_fType & fPropArray) == 0 && i > 0)
  99. || (_fType & fPropString) )
  100. throw GMException(EC_PROP_MISUSE,"not a numeric property or not an array");
  101. if ( i >= _vrValues.size() )
  102. throw GMException(EC_PROP_MISUSE,"property index out of range");
  103. return _vrValues[i];
  104. }
  105. void PROPMBN :: Reset ()
  106. {
  107. _vrValues.clear();
  108. _vzsrStrings.clear();
  109. }
  110. void PROPMBN :: Set ( ZSREF zsr )
  111. {
  112. if ( (_fType & fPropString) == 0 )
  113. throw GMException(EC_PROP_MISUSE,"not a string property");
  114. Reset();
  115. _vzsrStrings.push_back(zsr);
  116. }
  117. void PROPMBN :: Set ( REAL r )
  118. {
  119. if ( _fType & fPropString )
  120. throw GMException(EC_PROP_MISUSE,"not a numeric property");
  121. Reset();
  122. _vrValues.push_back(r);
  123. }
  124. void PROPMBN :: Add ( ZSREF zsr )
  125. {
  126. if ( (_fType & (fPropArray | fPropString)) == 0 )
  127. throw GMException(EC_PROP_MISUSE,"not a string array property");
  128. _vzsrStrings.push_back(zsr);
  129. }
  130. void PROPMBN :: Add ( REAL r )
  131. {
  132. if ( (_fType & fPropArray) == 0 )
  133. throw GMException(EC_PROP_MISUSE,"not a numeric array property");
  134. _vrValues.push_back(r);
  135. }
  136. PROPMBN * LTBNPROP :: PFind ( ZSREF zsrProp )
  137. {
  138. iterator itlt = find( begin(), end(), zsrProp );
  139. if ( itlt == end() )
  140. return NULL;
  141. return & (*itlt);
  142. }
  143. const PROPMBN * LTBNPROP :: PFind ( ZSREF zsrProp ) const
  144. {
  145. const_iterator itlt = find( begin(), end(), zsrProp );
  146. if ( itlt == end() )
  147. return NULL;
  148. return & (*itlt);
  149. }
  150. bool LTBNPROP :: Update ( const PROPMBN & bnp )
  151. {
  152. PROPMBN * pprop = PFind( bnp.ZsrPropType() );
  153. if ( pprop )
  154. *pprop = bnp;
  155. else
  156. push_back( bnp );
  157. return pprop != NULL;
  158. }
  159. // Force the list to contain only unique elements. Note that
  160. // the act of sorting and uniquing will discard duplicates randomly.
  161. bool LTBNPROP :: Uniqify ()
  162. {
  163. int cBefore = size();
  164. sort();
  165. unique();
  166. return size() == cBefore;
  167. }
  168. // Clone from another list with another symbol table
  169. void LTBNPROP :: Clone (
  170. MODEL & model,
  171. const MODEL & modelOther,
  172. const LTBNPROP & ltbnOther )
  173. {
  174. for ( const_iterator itlt = ltbnOther.begin(); itlt != ltbnOther.end(); itlt++ )
  175. {
  176. const PROPMBN & prpOther = (*itlt);
  177. // Note that the dynamic cast below will test for failure to
  178. // find property type object
  179. GOBJMBN * pgobj = model.PgobjFind( prpOther.ZsrPropType() );
  180. ASSERT_THROW( pgobj != NULL,
  181. EC_INTERNAL_ERROR,
  182. "missing property type in target network during cloning" );
  183. GOBJPROPTYPE * pgobjPropType;
  184. DynCastThrow( pgobj, pgobjPropType );
  185. PROPMBN prp;
  186. prp.Init( *pgobjPropType );
  187. model.Mpsymtbl().CloneVzsref( modelOther.Mpsymtbl(),
  188. prpOther._vzsrStrings,
  189. prp._vzsrStrings );
  190. prp._vrValues = prpOther._vrValues;
  191. push_back( prp );
  192. }
  193. }
  194. static
  195. struct MPVOIPROPSZC
  196. {
  197. ESTDPROP _eProp;
  198. SZC _szcProp;
  199. }
  200. vVoiProp [] =
  201. {
  202. { ESTDP_label, "MS_label" },
  203. { ESTDP_cost_fix, "MS_cost_fix" },
  204. { ESTDP_cost_observe, "MS_cost_observe" },
  205. { ESTDP_category, "MS_category" },
  206. { ESTDP_normalState, "MS_normalState" },
  207. { ESTDP_max, NULL }
  208. };
  209. static
  210. struct MPLBLSZC
  211. {
  212. ESTDLBL _eLbl;
  213. SZC _szcLbl;
  214. }
  215. vLblSzc [] =
  216. {
  217. { ESTDLBL_other, "other" },
  218. { ESTDLBL_hypo, "hypothesis" },
  219. { ESTDLBL_info, "informational" },
  220. { ESTDLBL_problem, "problem" },
  221. { ESTDLBL_fixobs, "fixobs" },
  222. { ESTDLBL_fixunobs, "fixunobs" },
  223. { ESTDLBL_unfix, "unfixable" },
  224. { ESTDLBL_config, "configuration" },
  225. { ESTDLBL_max, NULL }
  226. };
  227. SZC PROPMGR :: SzcLbl ( int iLbl )
  228. {
  229. SZC szcOther = NULL;
  230. for ( int i = 0; vLblSzc[i]._szcLbl; i++ )
  231. {
  232. if ( vLblSzc[i]._eLbl == iLbl )
  233. return vLblSzc[i]._szcLbl;
  234. if ( vLblSzc[i]._eLbl == ESTDLBL_other )
  235. szcOther = vLblSzc[i]._szcLbl;
  236. }
  237. return szcOther;
  238. }
  239. PROPMGR :: PROPMGR ( MODEL & model )
  240. : _model(model)
  241. {
  242. // Locate all the standard property types; save their
  243. // name references whether or not they've been declared.
  244. SZC szcProp;
  245. for ( int i = 0; szcProp = vVoiProp[i]._szcProp ; i++ )
  246. {
  247. GOBJPROPTYPE * ppt = NULL;
  248. _vzsrPropType.push_back( _model.Mpsymtbl().intern( szcProp ) );
  249. GOBJMBN * pgobj = _model.PgobjFind( szcProp );
  250. if ( pgobj )
  251. {
  252. if ( pgobj->EType() == GOBJMBN::EBNO_PROP_TYPE )
  253. {
  254. DynCastThrow( pgobj, ppt );
  255. }
  256. }
  257. _vPropMap[i] = ppt;
  258. }
  259. // If we found "MS_label", prepare the correspondence table
  260. GOBJPROPTYPE * pptLabel = _vPropMap[ESTDP_label];
  261. if ( pptLabel && (pptLabel->FPropType() & fPropChoice) > 0 )
  262. {
  263. SZC szcChoice;
  264. const VZSREF & vzsr = pptLabel->VzsrChoice();
  265. _vUserToLbl.resize( vzsr.size() );
  266. // Clear the user-to-standard-label map
  267. for ( i = 0; i < _vUserToLbl.size(); )
  268. _vUserToLbl[i++] = -1;
  269. for ( i = 0; szcChoice = vLblSzc[i]._szcLbl; i++ )
  270. {
  271. int iLbl = -1;
  272. ZSREF zsrChoice = _model.Mpsymtbl().intern( szcChoice );
  273. for ( int j = 0; j < vzsr.size(); j++ )
  274. {
  275. if ( zsrChoice == vzsr[j] )
  276. {
  277. iLbl = j;
  278. // Mark which standard label this user element corresponds to
  279. _vUserToLbl[iLbl] = i;
  280. break;
  281. }
  282. }
  283. // Mark which user element this standard label corresponds to
  284. _vLblToUser[i] = iLbl;
  285. }
  286. }
  287. else
  288. { // Clear the correspondence information
  289. for ( i = 0; i < ESTDLBL_max; i++ )
  290. {
  291. _vLblToUser[i] = -1;
  292. }
  293. }
  294. }
  295. GOBJPROPTYPE * PROPMGR :: PPropType ( ESTDPROP evp )
  296. {
  297. return _vPropMap[evp];
  298. }
  299. // Return the name of the standard property
  300. ZSREF PROPMGR :: ZsrPropType ( ESTDPROP evp )
  301. {
  302. ASSERT_THROW( evp >= 0 && evp < ESTDP_max,
  303. EC_INTERNAL_ERROR,
  304. "invalid property type usage" );
  305. return _vzsrPropType[evp];
  306. }
  307. // Find a standard property in a property list
  308. PROPMBN * PROPMGR :: PFind ( LTBNPROP & ltprop, ESTDPROP estd )
  309. {
  310. return ltprop.PFind( ZsrPropType(estd) ) ;
  311. }
  312. // Find a standard property in the associated model's property list
  313. PROPMBN * PROPMGR :: PFind ( ESTDPROP estd )
  314. {
  315. return _model.LtProp().PFind( ZsrPropType(estd) ) ;
  316. }
  317. // Find a standard property in a node's property list
  318. PROPMBN * PROPMGR :: PFind ( GNODEMBN & gnd, ESTDPROP estd )
  319. {
  320. return gnd.LtProp().PFind( ZsrPropType(estd) ) ;
  321. }