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.

891 lines
20 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  2. #ifndef __SNMPCONT_H
  3. #define __SNMPCONT_H
  4. #include <provexpt.h>
  5. #include <ScopeGuard.h>
  6. template<class TYPE, class ARG_TYPE>
  7. class SnmpList
  8. {
  9. private:
  10. CCriticalSection * criticalSection ;
  11. CList <TYPE, ARG_TYPE> clist ;
  12. protected:
  13. public:
  14. SnmpList ( BOOL threadSafeArg = FALSE ) ;
  15. virtual ~SnmpList () ;
  16. int GetCount() const;
  17. BOOL IsEmpty() const;
  18. TYPE& GetHead();
  19. TYPE GetHead() const;
  20. TYPE& GetTail();
  21. TYPE GetTail() const;
  22. TYPE RemoveHead();
  23. TYPE RemoveTail();
  24. POSITION AddHead(ARG_TYPE newElement);
  25. POSITION AddTail(ARG_TYPE newElement);
  26. void AddHead(SnmpList<TYPE,ARG_TYPE>* pNewList);
  27. void AddTail(SnmpList<TYPE,ARG_TYPE>* pNewList);
  28. void RemoveAll();
  29. POSITION GetHeadPosition() const;
  30. POSITION GetTailPosition() const;
  31. TYPE& GetNext(POSITION& rPosition);
  32. TYPE GetNext(POSITION& rPosition) const;
  33. TYPE& GetPrev(POSITION& rPosition);
  34. TYPE GetPrev(POSITION& rPosition) const;
  35. TYPE& GetAt(POSITION position);
  36. TYPE GetAt(POSITION position) const;
  37. void SetAt(POSITION pos, ARG_TYPE newElement);
  38. void RemoveAt(POSITION position);
  39. POSITION InsertBefore(POSITION position, ARG_TYPE newElement);
  40. POSITION InsertAfter(POSITION position, ARG_TYPE newElement);
  41. POSITION Find(ARG_TYPE searchValue, POSITION startAfter = NULL) const;
  42. POSITION FindIndex(int nIndex) const;
  43. } ;
  44. template<class TYPE, class ARG_TYPE>
  45. SnmpList <TYPE,ARG_TYPE>:: SnmpList ( BOOL threadSafeArg ) : criticalSection ( NULL )
  46. {
  47. if ( threadSafeArg )
  48. criticalSection = new CCriticalSection ;
  49. else
  50. criticalSection = NULL ;
  51. }
  52. template<class TYPE, class ARG_TYPE>
  53. SnmpList <TYPE,ARG_TYPE> :: ~SnmpList ()
  54. {
  55. if ( criticalSection )
  56. delete criticalSection ;
  57. }
  58. template<class TYPE, class ARG_TYPE>
  59. int SnmpList <TYPE,ARG_TYPE> :: GetCount() const
  60. {
  61. if ( criticalSection )
  62. {
  63. criticalSection->Lock () ;
  64. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  65. int count = clist.GetCount () ;
  66. return count ;
  67. }
  68. else
  69. {
  70. return clist.GetCount () ;
  71. }
  72. }
  73. template<class TYPE, class ARG_TYPE>
  74. BOOL SnmpList <TYPE,ARG_TYPE> :: IsEmpty() const
  75. {
  76. if ( criticalSection )
  77. {
  78. criticalSection->Lock () ;
  79. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  80. BOOL isEmpty = clist.IsEmpty () ;
  81. return isEmpty ;
  82. }
  83. else
  84. {
  85. return clist.IsEmpty () ;
  86. }
  87. }
  88. template<class TYPE, class ARG_TYPE>
  89. TYPE &SnmpList <TYPE,ARG_TYPE> :: GetHead ()
  90. {
  91. if ( criticalSection )
  92. {
  93. criticalSection->Lock () ;
  94. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  95. TYPE &head = clist.GetHead () ;
  96. return head;
  97. }
  98. else
  99. {
  100. return clist.GetHead () ;
  101. }
  102. }
  103. template<class TYPE, class ARG_TYPE>
  104. TYPE SnmpList <TYPE,ARG_TYPE> :: GetHead () const
  105. {
  106. if ( criticalSection )
  107. {
  108. criticalSection->Lock () ;
  109. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  110. TYPE head = clist.GetHead () ;
  111. return head ;
  112. }
  113. else
  114. {
  115. return clist.GetHead () ;
  116. }
  117. }
  118. template<class TYPE, class ARG_TYPE>
  119. TYPE &SnmpList <TYPE,ARG_TYPE> :: GetTail()
  120. {
  121. if ( criticalSection )
  122. {
  123. criticalSection->Lock () ;
  124. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  125. TYPE &tail = clist.GetTail () ;
  126. return tail ;
  127. }
  128. else
  129. {
  130. return clist.GetTail () ;
  131. }
  132. }
  133. template<class TYPE, class ARG_TYPE>
  134. TYPE SnmpList <TYPE,ARG_TYPE> :: GetTail() const
  135. {
  136. if ( criticalSection )
  137. {
  138. criticalSection->Lock () ;
  139. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  140. TYPE tail = clist.GetTail () ;
  141. return tail ;
  142. }
  143. else
  144. {
  145. return clist.GetTail () ;
  146. }
  147. }
  148. template<class TYPE, class ARG_TYPE>
  149. TYPE SnmpList <TYPE,ARG_TYPE> :: RemoveHead()
  150. {
  151. if ( criticalSection )
  152. {
  153. criticalSection->Lock () ;
  154. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  155. TYPE head = clist.RemoveHead () ;
  156. return head ;
  157. }
  158. else
  159. {
  160. return clist.RemoveHead () ;
  161. }
  162. }
  163. template<class TYPE, class ARG_TYPE>
  164. TYPE SnmpList <TYPE,ARG_TYPE> :: RemoveTail()
  165. {
  166. if ( criticalSection )
  167. {
  168. criticalSection->Lock () ;
  169. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  170. TYPE tail = clist.RemoveTail () ;
  171. return tail ;
  172. }
  173. else
  174. {
  175. return clist.RemoveTail () ;
  176. }
  177. }
  178. template<class TYPE, class ARG_TYPE>
  179. POSITION SnmpList <TYPE,ARG_TYPE> :: AddHead(ARG_TYPE newElement)
  180. {
  181. if ( criticalSection )
  182. {
  183. criticalSection->Lock () ;
  184. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  185. POSITION position = clist.AddHead ( newElement ) ;
  186. return position ;
  187. }
  188. else
  189. {
  190. return clist.AddHead ( newElement ) ;
  191. }
  192. }
  193. template<class TYPE, class ARG_TYPE>
  194. POSITION SnmpList <TYPE,ARG_TYPE> :: AddTail(ARG_TYPE newElement)
  195. {
  196. if ( criticalSection )
  197. {
  198. criticalSection->Lock () ;
  199. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  200. POSITION position = clist.AddTail ( newElement ) ;
  201. return position ;
  202. }
  203. else
  204. {
  205. return clist.AddTail ( newElement ) ;
  206. }
  207. }
  208. template<class TYPE, class ARG_TYPE>
  209. void SnmpList <TYPE,ARG_TYPE> :: AddHead(SnmpList<TYPE,ARG_TYPE> *pNewList)
  210. {
  211. if ( criticalSection )
  212. {
  213. criticalSection->Lock () ;
  214. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  215. clist.AddHead ( pNewList->clist ) ;
  216. }
  217. else
  218. {
  219. clist.AddHead ( pNewList->clist ) ;
  220. }
  221. }
  222. template<class TYPE, class ARG_TYPE>
  223. void SnmpList <TYPE,ARG_TYPE> :: AddTail(SnmpList<TYPE,ARG_TYPE> *pNewList)
  224. {
  225. if ( criticalSection )
  226. {
  227. criticalSection->Lock () ;
  228. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  229. clist.AddTail ( pNewList->clist ) ;
  230. }
  231. else
  232. {
  233. clist.AddTail ( pNewList->clist ) ;
  234. }
  235. }
  236. template<class TYPE, class ARG_TYPE>
  237. void SnmpList <TYPE,ARG_TYPE> :: RemoveAll ()
  238. {
  239. if ( criticalSection )
  240. {
  241. criticalSection->Lock () ;
  242. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  243. clist.RemoveAll () ;
  244. }
  245. else
  246. {
  247. clist.RemoveAll () ;
  248. }
  249. }
  250. template<class TYPE, class ARG_TYPE>
  251. POSITION SnmpList <TYPE,ARG_TYPE> :: GetHeadPosition() const
  252. {
  253. if ( criticalSection )
  254. {
  255. criticalSection->Lock () ;
  256. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  257. POSITION position = clist.GetHeadPosition () ;
  258. return position ;
  259. }
  260. else
  261. {
  262. return clist.GetHeadPosition () ;
  263. }
  264. }
  265. template<class TYPE, class ARG_TYPE>
  266. POSITION SnmpList <TYPE,ARG_TYPE> :: GetTailPosition() const
  267. {
  268. if ( criticalSection )
  269. {
  270. criticalSection->Lock () ;
  271. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  272. POSITION position = clist.GetTailPosition () ;
  273. return position ;
  274. }
  275. else
  276. {
  277. return clist.GetTailPosition () ;
  278. }
  279. }
  280. template<class TYPE, class ARG_TYPE>
  281. TYPE& SnmpList <TYPE,ARG_TYPE> :: GetNext(POSITION& rPosition)
  282. {
  283. if ( criticalSection )
  284. {
  285. criticalSection->Lock () ;
  286. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  287. TYPE &type = clist.GetNext ( rPosition ) ;
  288. return type ;
  289. }
  290. else
  291. {
  292. return clist.GetNext ( rPosition ) ;
  293. }
  294. }
  295. template<class TYPE, class ARG_TYPE>
  296. TYPE SnmpList <TYPE,ARG_TYPE> :: GetNext(POSITION& rPosition) const
  297. {
  298. if ( criticalSection )
  299. {
  300. criticalSection->Lock () ;
  301. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  302. TYPE type = clist.GetNext ( rPosition ) ;
  303. return type ;
  304. }
  305. else
  306. {
  307. return clist.GetNext ( rPosition ) ;
  308. }
  309. }
  310. template<class TYPE, class ARG_TYPE>
  311. TYPE& SnmpList <TYPE,ARG_TYPE> :: GetPrev(POSITION& rPosition)
  312. {
  313. if ( criticalSection )
  314. {
  315. criticalSection->Lock () ;
  316. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  317. TYPE &type = clist.GetPrev ( rPosition ) ;
  318. return type ;
  319. }
  320. else
  321. {
  322. return clist.GetPrev ( rPosition ) ;
  323. }
  324. }
  325. template<class TYPE, class ARG_TYPE>
  326. TYPE SnmpList <TYPE,ARG_TYPE> :: GetPrev(POSITION& rPosition) const
  327. {
  328. if ( criticalSection )
  329. {
  330. criticalSection->Lock () ;
  331. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  332. TYPE type = clist.GetPrev ( rPosition ) ;
  333. return type ;
  334. }
  335. else
  336. {
  337. return clist.GetPrev ( rPosition ) ;
  338. }
  339. }
  340. template<class TYPE, class ARG_TYPE>
  341. TYPE& SnmpList <TYPE,ARG_TYPE> :: GetAt(POSITION rPosition)
  342. {
  343. if ( criticalSection )
  344. {
  345. criticalSection->Lock () ;
  346. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  347. TYPE &type = clist.GetAt ( rPosition ) ;
  348. return type ;
  349. }
  350. else
  351. {
  352. return clist.GetAt ( rPosition ) ;
  353. }
  354. }
  355. template<class TYPE, class ARG_TYPE>
  356. TYPE SnmpList <TYPE,ARG_TYPE> :: GetAt(POSITION rPosition) const
  357. {
  358. if ( criticalSection )
  359. {
  360. criticalSection->Lock () ;
  361. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  362. TYPE type = clist.GetAt ( rPosition ) ;
  363. return type ;
  364. }
  365. else
  366. {
  367. return clist.GetAt ( rPosition ) ;
  368. }
  369. }
  370. template<class TYPE, class ARG_TYPE>
  371. void SnmpList <TYPE,ARG_TYPE> :: SetAt(POSITION pos, ARG_TYPE newElement)
  372. {
  373. if ( criticalSection )
  374. {
  375. criticalSection->Lock () ;
  376. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  377. clist.SetAt ( pos , newElement ) ;
  378. }
  379. else
  380. {
  381. clist.SetAt ( pos , newElement ) ;
  382. }
  383. }
  384. template<class TYPE, class ARG_TYPE>
  385. void SnmpList <TYPE,ARG_TYPE> :: RemoveAt(POSITION position)
  386. {
  387. if ( criticalSection )
  388. {
  389. criticalSection->Lock () ;
  390. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  391. clist.RemoveAt ( position ) ;
  392. }
  393. else
  394. {
  395. clist.RemoveAt ( position ) ;
  396. }
  397. }
  398. template<class TYPE, class ARG_TYPE>
  399. POSITION SnmpList <TYPE,ARG_TYPE> :: InsertBefore(POSITION position, ARG_TYPE newElement)
  400. {
  401. if ( criticalSection )
  402. {
  403. criticalSection->Lock () ;
  404. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  405. POSITION position = clist.InsertBefore ( position , newElement ) ;
  406. return position ;
  407. }
  408. else
  409. {
  410. return clist.InsertBefore ( position , newElement ) ;
  411. }
  412. }
  413. template<class TYPE, class ARG_TYPE>
  414. POSITION SnmpList <TYPE,ARG_TYPE> :: InsertAfter(POSITION position, ARG_TYPE newElement)
  415. {
  416. if ( criticalSection )
  417. {
  418. criticalSection->Lock () ;
  419. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  420. POSITION position = clist.InsertAfter ( position , newElement ) ;
  421. return position ;
  422. }
  423. else
  424. {
  425. return clist.InsertAfter ( position , newElement ) ;
  426. }
  427. }
  428. template<class TYPE, class ARG_TYPE>
  429. POSITION SnmpList <TYPE,ARG_TYPE> :: Find(ARG_TYPE searchValue, POSITION startAfter ) const
  430. {
  431. if ( criticalSection )
  432. {
  433. criticalSection->Lock () ;
  434. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  435. POSITION position = clist.Find ( searchValue , startAfter ) ;
  436. return position ;
  437. }
  438. else
  439. {
  440. return clist.Find ( searchValue , startAfter ) ;
  441. }
  442. }
  443. template<class TYPE, class ARG_TYPE>
  444. POSITION SnmpList <TYPE,ARG_TYPE> :: FindIndex(int nIndex) const
  445. {
  446. if ( criticalSection )
  447. {
  448. criticalSection->Lock () ;
  449. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  450. POSITION position = clist.Find ( nIndex ) ;
  451. return position ;
  452. }
  453. else
  454. {
  455. return clist.Find ( nIndex ) ;
  456. }
  457. }
  458. template<class TYPE, class ARG_TYPE>
  459. class SnmpStack : public SnmpList<TYPE,ARG_TYPE>
  460. {
  461. private:
  462. CCriticalSection * criticalSection ;
  463. protected:
  464. public:
  465. SnmpStack ( BOOL threadSafeArg = FALSE ) ;
  466. virtual ~SnmpStack () ;
  467. void Add ( ARG_TYPE type ) ;
  468. TYPE Get () ;
  469. TYPE Delete () ;
  470. } ;
  471. template<class TYPE, class ARG_TYPE>
  472. SnmpStack <TYPE, ARG_TYPE> :: SnmpStack ( BOOL threadSafeArg ) :
  473. SnmpList<TYPE,ARG_TYPE> ( FALSE ) ,
  474. criticalSection ( NULL )
  475. {
  476. if ( threadSafeArg )
  477. criticalSection = new CCriticalSection ;
  478. else
  479. criticalSection = NULL ;
  480. }
  481. template<class TYPE, class ARG_TYPE>
  482. SnmpStack <TYPE, ARG_TYPE> :: ~SnmpStack ()
  483. {
  484. if ( criticalSection )
  485. delete criticalSection ;
  486. }
  487. template<class TYPE, class ARG_TYPE>
  488. void SnmpStack <TYPE, ARG_TYPE> :: Add ( ARG_TYPE type )
  489. {
  490. if ( criticalSection )
  491. {
  492. criticalSection->Lock () ;
  493. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  494. AddHead ( type ) ;
  495. }
  496. else
  497. {
  498. AddHead ( type ) ;
  499. }
  500. }
  501. template<class TYPE, class ARG_TYPE>
  502. TYPE SnmpStack <TYPE, ARG_TYPE> :: Get ()
  503. {
  504. if ( criticalSection )
  505. {
  506. criticalSection->Lock () ;
  507. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  508. TYPE type = GetHead () ;
  509. return type ;
  510. }
  511. else
  512. {
  513. return GetHead () ;
  514. }
  515. }
  516. template<class TYPE, class ARG_TYPE>
  517. TYPE SnmpStack <TYPE,ARG_TYPE> :: Delete ()
  518. {
  519. if ( criticalSection )
  520. {
  521. criticalSection->Lock () ;
  522. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  523. TYPE type = RemoveHead () ;
  524. return type ;
  525. }
  526. else
  527. {
  528. return RemoveHead () ;
  529. }
  530. }
  531. template<class TYPE, class ARG_TYPE>
  532. class SnmpQueue : public SnmpList<TYPE,ARG_TYPE>
  533. {
  534. private:
  535. CCriticalSection * criticalSection ;
  536. protected:
  537. public:
  538. SnmpQueue ( BOOL threadSafeArg = FALSE ) ;
  539. virtual ~SnmpQueue () ;
  540. void Add ( ARG_TYPE type ) ;
  541. TYPE Get () ;
  542. TYPE Delete () ;
  543. void Rotate () ;
  544. } ;
  545. template<class TYPE, class ARG_TYPE>
  546. SnmpQueue <TYPE, ARG_TYPE> :: SnmpQueue ( BOOL threadSafeArg ) :
  547. SnmpList<TYPE,ARG_TYPE> ( FALSE ) ,
  548. criticalSection ( NULL )
  549. {
  550. if ( threadSafeArg )
  551. criticalSection = new CCriticalSection ;
  552. else
  553. criticalSection = NULL ;
  554. }
  555. template<class TYPE, class ARG_TYPE>
  556. SnmpQueue <TYPE, ARG_TYPE> :: ~SnmpQueue ()
  557. {
  558. if ( criticalSection )
  559. delete criticalSection ;
  560. }
  561. template<class TYPE, class ARG_TYPE>
  562. void SnmpQueue <TYPE, ARG_TYPE> :: Add ( ARG_TYPE type )
  563. {
  564. if ( criticalSection )
  565. {
  566. criticalSection->Lock () ;
  567. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  568. AddTail ( type ) ;
  569. }
  570. else
  571. {
  572. AddTail ( type ) ;
  573. }
  574. }
  575. template<class TYPE, class ARG_TYPE>
  576. TYPE SnmpQueue <TYPE, ARG_TYPE> :: Get ()
  577. {
  578. if ( criticalSection )
  579. {
  580. criticalSection->Lock () ;
  581. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  582. TYPE type = GetHead () ;
  583. return type ;
  584. }
  585. else
  586. {
  587. return GetHead () ;
  588. }
  589. }
  590. template<class TYPE, class ARG_TYPE>
  591. TYPE SnmpQueue <TYPE, ARG_TYPE> :: Delete ()
  592. {
  593. if ( criticalSection )
  594. {
  595. criticalSection->Lock () ;
  596. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  597. TYPE type = RemoveHead () ;
  598. return type ;
  599. }
  600. else
  601. {
  602. return RemoveHead () ;
  603. }
  604. }
  605. template<class TYPE, class ARG_TYPE>
  606. void SnmpQueue <TYPE, ARG_TYPE> :: Rotate ()
  607. {
  608. if ( criticalSection )
  609. {
  610. criticalSection->Lock () ;
  611. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  612. TYPE type = Delete () ;
  613. Add ( type ) ;
  614. }
  615. else
  616. {
  617. TYPE type = Delete () ;
  618. Add ( type ) ;
  619. }
  620. }
  621. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  622. class SnmpMap
  623. {
  624. private:
  625. CCriticalSection * criticalSection ;
  626. CMap <KEY, ARG_KEY, VALUE, ARG_VALUE> cmap ;
  627. protected:
  628. public:
  629. SnmpMap ( BOOL threadSafe = FALSE ) ;
  630. virtual ~SnmpMap () ;
  631. int GetCount () const ;
  632. BOOL IsEmpty () const ;
  633. BOOL Lookup(ARG_KEY key, VALUE& rValue) const ;
  634. VALUE& operator[](ARG_KEY key) ;
  635. void SetAt(ARG_KEY key, ARG_VALUE newValue) ;
  636. BOOL RemoveKey(ARG_KEY key) ;
  637. void RemoveAll () ;
  638. POSITION GetStartPosition() const ;
  639. void GetNextAssoc(POSITION& rNextPosition, KEY& rKey, VALUE& rValue) const ;
  640. BOOL GetCurrentAssoc(POSITION rPosition, KEY& rKey, VALUE& rValue) const;
  641. } ;
  642. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  643. SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: SnmpMap ( BOOL threadSafeArg ) : criticalSection ( NULL )
  644. {
  645. if ( threadSafeArg )
  646. criticalSection = new CCriticalSection ;
  647. else
  648. criticalSection = FALSE ;
  649. }
  650. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  651. SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: ~SnmpMap ()
  652. {
  653. if ( criticalSection )
  654. delete criticalSection ;
  655. }
  656. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  657. int SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: GetCount() const
  658. {
  659. if ( criticalSection )
  660. {
  661. criticalSection->Lock () ;
  662. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  663. int count = cmap.GetCount () ;
  664. return count ;
  665. }
  666. else
  667. {
  668. return cmap.GetCount () ;
  669. }
  670. }
  671. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  672. BOOL SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: IsEmpty() const
  673. {
  674. if ( criticalSection )
  675. {
  676. criticalSection->Lock () ;
  677. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  678. BOOL isEmpty = cmap.IsEmpty () ;
  679. return isEmpty ;
  680. }
  681. else
  682. {
  683. return cmap.IsEmpty () ;
  684. }
  685. }
  686. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  687. BOOL SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: Lookup(ARG_KEY key, VALUE& rValue) const
  688. {
  689. if ( criticalSection )
  690. {
  691. criticalSection->Lock () ;
  692. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  693. BOOL lookup = cmap.Lookup ( key , rValue ) ;
  694. return lookup ;
  695. }
  696. else
  697. {
  698. return cmap.Lookup ( key , rValue ) ;
  699. }
  700. }
  701. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  702. VALUE& SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: operator[](ARG_KEY key)
  703. {
  704. if ( criticalSection )
  705. {
  706. criticalSection->Lock () ;
  707. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  708. VALUE &value = cmap.operator [] ( key ) ;
  709. return value ;
  710. }
  711. else
  712. {
  713. return cmap.operator [] ( key ) ;
  714. }
  715. }
  716. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  717. void SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: SetAt(ARG_KEY key, ARG_VALUE newValue)
  718. {
  719. if ( criticalSection )
  720. {
  721. criticalSection->Lock () ;
  722. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  723. cmap.SetAt ( key , newValue ) ;
  724. }
  725. else
  726. {
  727. cmap.SetAt ( key , newValue ) ;
  728. }
  729. }
  730. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  731. BOOL SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: RemoveKey(ARG_KEY key)
  732. {
  733. if ( criticalSection )
  734. {
  735. criticalSection->Lock () ;
  736. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  737. BOOL removeKey = cmap.RemoveKey ( key ) ;
  738. return removeKey ;
  739. }
  740. else
  741. {
  742. return cmap.RemoveKey ( key ) ;
  743. }
  744. }
  745. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  746. void SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: RemoveAll()
  747. {
  748. if ( criticalSection )
  749. {
  750. criticalSection->Lock () ;
  751. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  752. cmap.RemoveAll () ;
  753. }
  754. else
  755. {
  756. cmap.RemoveAll () ;
  757. }
  758. }
  759. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  760. POSITION SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE> :: GetStartPosition() const
  761. {
  762. if ( criticalSection )
  763. {
  764. criticalSection->Lock () ;
  765. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  766. POSITION position = cmap.GetStartPosition () ;
  767. return position ;
  768. }
  769. else
  770. {
  771. return cmap.GetStartPosition () ;
  772. }
  773. }
  774. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  775. void SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE>:: GetNextAssoc(POSITION& rNextPosition, KEY& rKey, VALUE& rValue) const
  776. {
  777. if ( criticalSection )
  778. {
  779. criticalSection->Lock () ;
  780. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  781. cmap.GetNextAssoc ( rNextPosition , rKey , rValue ) ;
  782. }
  783. else
  784. {
  785. cmap.GetNextAssoc ( rNextPosition , rKey , rValue ) ;
  786. }
  787. }
  788. template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
  789. BOOL SnmpMap <KEY, ARG_KEY, VALUE, ARG_VALUE>:: GetCurrentAssoc(POSITION rPosition, KEY& rKey, VALUE& rValue) const
  790. {
  791. BOOL t_Status ;
  792. if ( criticalSection )
  793. {
  794. criticalSection->Lock () ;
  795. ScopeGuard t_1 = MakeObjGuard ( *criticalSection , CCriticalSection :: Unlock ) ;
  796. t_Status = cmap.GetCurrentAssoc ( rPosition , rKey , rValue ) ;
  797. }
  798. else
  799. {
  800. t_Status = cmap.GetCurrentAssoc ( rPosition , rKey , rValue ) ;
  801. }
  802. return t_Status ;
  803. }
  804. #endif // __SNMPCONT_H