00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ACE_MAP_MANAGER_H
00014 #define ACE_MAP_MANAGER_H
00015
00016 #include "ace/pre.h"
00017
00018 #include "ace/config-all.h"
00019
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif
00023
00024 #include "ace/Basic_Types.h"
00025 #include "ace/Global_Macros.h"
00026 #include "ace/Default_Constants.h"
00027
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029
00030
00031 class ACE_Allocator;
00032
00033
00034
00035
00036
00037
00038 template <class EXT_ID, class INT_ID>
00039 class ACE_Map_Entry
00040 {
00041 public:
00042 # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
00043
00044
00045 ~ACE_Map_Entry (void);
00046 # endif
00047
00048
00049 EXT_ID ext_id_;
00050
00051
00052 INT_ID int_id_;
00053
00054
00055 void dump (void) const;
00056
00057
00058 ACE_ALLOC_HOOK_DECLARE;
00059
00060
00061
00062
00063
00064 ACE_UINT32 next (void) const;
00065
00066
00067 void next (ACE_UINT32 n);
00068
00069
00070 ACE_UINT32 prev (void) const;
00071
00072
00073 void prev (ACE_UINT32 p);
00074
00075
00076 ACE_UINT32 next_;
00077
00078
00079 ACE_UINT32 prev_;
00080
00081 #if defined (ACE_HAS_LAZY_MAP_MANAGER)
00082
00083
00084 int free_;
00085
00086 #endif
00087
00088 };
00089
00090
00091 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00092 class ACE_Map_Iterator_Base;
00093
00094
00095 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00096 class ACE_Map_Const_Iterator_Base;
00097
00098
00099 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00100 class ACE_Map_Iterator;
00101
00102
00103 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00104 class ACE_Map_Const_Iterator;
00105
00106
00107 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00108 class ACE_Map_Reverse_Iterator;
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00127 class ACE_Map_Manager
00128 {
00129 public:
00130 friend class ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>;
00131 friend class ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>;
00132 friend class ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
00133 friend class ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
00134 friend class ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
00135
00136
00137 typedef EXT_ID KEY;
00138 typedef INT_ID VALUE;
00139 typedef ACE_LOCK lock_type;
00140 typedef ACE_Map_Entry<EXT_ID, INT_ID> ENTRY;
00141 typedef ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> ITERATOR;
00142 typedef ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> CONST_ITERATOR;
00143 typedef ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> REVERSE_ITERATOR;
00144
00145 typedef ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> iterator;
00146 typedef ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> const_iterator;
00147 typedef ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> reverse_iterator;
00148
00149
00150
00151 ACE_Map_Manager (ACE_Allocator *alloc = 0);
00152
00153
00154 ACE_Map_Manager (size_t size,
00155 ACE_Allocator *alloc = 0);
00156
00157
00158 int open (size_t length = ACE_DEFAULT_MAP_SIZE,
00159 ACE_Allocator *alloc = 0);
00160
00161
00162
00163 int close (void);
00164
00165
00166
00167 ~ACE_Map_Manager (void);
00168
00169
00170
00171
00172
00173
00174
00175
00176 int bind (const EXT_ID &ext_id,
00177 const INT_ID &int_id);
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 int rebind (const EXT_ID &ext_id,
00191 const INT_ID &int_id,
00192 EXT_ID &old_ext_id,
00193 INT_ID &old_int_id);
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 int rebind (const EXT_ID &ext_id,
00205 const INT_ID &int_id,
00206 INT_ID &old_int_id);
00207
00208
00209
00210 int rebind (const EXT_ID &ext_id,
00211 const INT_ID &int_id);
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 int trybind (const EXT_ID &ext_id,
00222 INT_ID &int_id);
00223
00224
00225
00226
00227
00228
00229 int find (const EXT_ID &ext_id,
00230 INT_ID &int_id) const;
00231
00232
00233 int find (const EXT_ID &ext_id) const;
00234
00235
00236
00237
00238
00239
00240
00241 int unbind (const EXT_ID &ext_id);
00242
00243
00244
00245
00246
00247
00248 int unbind (const EXT_ID &ext_id,
00249 INT_ID &int_id);
00250
00251
00252
00253
00254 void unbind_all (void);
00255
00256
00257 size_t current_size (void) const;
00258
00259
00260 size_t total_size (void) const;
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 ACE_LOCK &mutex (void);
00271
00272
00273 void dump (void) const;
00274
00275
00276
00277
00278 ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> begin (void);
00279 ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> end (void);
00280
00281
00282 ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> rbegin (void);
00283 ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> rend (void);
00284
00285
00286 ACE_ALLOC_HOOK_DECLARE;
00287
00288 protected:
00289
00290
00291
00292
00293
00294
00295
00296
00297 int bind_i (const EXT_ID &ext_id,
00298 const INT_ID &int_id);
00299
00300
00301
00302 int shared_bind (const EXT_ID &ext_id,
00303 const INT_ID &int_id);
00304
00305
00306
00307 int rebind_i (const EXT_ID &ext_id,
00308 const INT_ID &int_id,
00309 EXT_ID &old_ext_id,
00310 INT_ID &old_int_id);
00311
00312
00313
00314 int rebind_i (const EXT_ID &ext_id,
00315 const INT_ID &int_id,
00316 INT_ID &old_int_id);
00317
00318
00319
00320 int rebind_i (const EXT_ID &ext_id,
00321 const INT_ID &int_id);
00322
00323
00324
00325 int trybind_i (const EXT_ID &ext_id,
00326 INT_ID &int_id);
00327
00328
00329
00330 int find_i (const EXT_ID &ext_id,
00331 INT_ID &int_id);
00332
00333
00334
00335 int find_and_return_index (const EXT_ID &ext_id,
00336 ACE_UINT32 &slot);
00337
00338
00339
00340 int unbind_i (const EXT_ID &ext_id,
00341 INT_ID &int_id);
00342
00343
00344
00345 int unbind_i (const EXT_ID &ext_id);
00346
00347
00348
00349 int unbind_and_return_index (const EXT_ID &ext_id,
00350 ACE_UINT32 &slot);
00351
00352
00353 void unbind_slot (ACE_UINT32 slot);
00354
00355
00356 int resize_i (ACE_UINT32 size);
00357
00358
00359 int close_i (void);
00360
00361
00362
00363 int equal (const EXT_ID &id1, const EXT_ID &id2);
00364
00365
00366
00367 ACE_UINT32 new_size (void);
00368
00369
00370
00371 void free_search_structure (void);
00372
00373
00374 ACE_UINT32 free_list_id (void) const;
00375
00376
00377 ACE_UINT32 occupied_list_id (void) const;
00378
00379
00380 int next_free (ACE_UINT32 &slot);
00381
00382
00383 void move_from_free_list_to_occupied_list (ACE_UINT32 slot);
00384
00385
00386 void move_from_occupied_list_to_free_list (ACE_UINT32 slot);
00387
00388 #if defined (ACE_HAS_LAZY_MAP_MANAGER)
00389
00390
00391
00392
00393
00394
00395
00396 void move_all_free_slots_from_occupied_list (void);
00397
00398 #endif
00399
00400
00401 void shared_move (ACE_UINT32 slot,
00402 ACE_Map_Entry<EXT_ID, INT_ID> ¤t_list,
00403 ACE_UINT32 current_list_id,
00404 ACE_Map_Entry<EXT_ID, INT_ID> &new_list,
00405 ACE_UINT32 new_list_id);
00406
00407
00408 ACE_Allocator *allocator_;
00409
00410
00411 mutable ACE_LOCK lock_;
00412
00413
00414 ACE_Map_Entry<EXT_ID, INT_ID> *search_structure_;
00415
00416
00417 ACE_UINT32 total_size_;
00418
00419
00420 ACE_UINT32 cur_size_;
00421
00422
00423 ACE_Map_Entry<EXT_ID, INT_ID> free_list_;
00424
00425
00426 ACE_Map_Entry<EXT_ID, INT_ID> occupied_list_;
00427
00428 enum
00429 {
00430
00431 MAX_EXPONENTIAL = 64 * 1024,
00432
00433
00434 LINEAR_INCREASE = 32 * 1024
00435 };
00436
00437 private:
00438
00439 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &))
00440 ACE_UNIMPLEMENTED_FUNC (ACE_Map_Manager (const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &))
00441 };
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00452 class ACE_Map_Iterator_Base
00453 {
00454 public:
00455
00456
00457
00458 ACE_Map_Iterator_Base (ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm);
00459
00460
00461
00462
00463
00464 int next (ACE_Map_Entry<EXT_ID, INT_ID> *&next_entry) const;
00465
00466
00467 int done (void) const;
00468
00469
00470 ACE_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
00471
00472
00473
00474 ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>& map (void);
00475
00476
00477 bool operator== (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
00478 bool operator!= (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
00479
00480
00481 ACE_ALLOC_HOOK_DECLARE;
00482
00483 protected:
00484
00485
00486 int forward_i (void);
00487
00488
00489
00490 int reverse_i (void);
00491
00492
00493 void dump_i (void) const;
00494
00495
00496 ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> *map_man_;
00497
00498
00499 ACE_UINT32 next_;
00500 };
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00511 class ACE_Map_Const_Iterator_Base
00512 {
00513 public:
00514
00515
00516
00517 ACE_Map_Const_Iterator_Base (const ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm);
00518
00519
00520
00521
00522
00523 int next (ACE_Map_Entry<EXT_ID, INT_ID> *&next_entry) const;
00524
00525
00526 int done (void) const;
00527
00528
00529 ACE_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
00530
00531
00532
00533 const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>& map (void) const;
00534
00535
00536 bool operator== (const ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
00537 bool operator!= (const ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
00538
00539
00540 ACE_ALLOC_HOOK_DECLARE;
00541
00542 protected:
00543
00544
00545 int forward_i (void);
00546
00547
00548
00549 int reverse_i (void);
00550
00551
00552 void dump_i (void) const;
00553
00554
00555 const ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> *map_man_;
00556
00557
00558 ACE_UINT32 next_;
00559 };
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00574 class ACE_Map_Iterator : public ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>
00575 {
00576 public:
00577
00578 ACE_Map_Iterator (ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
00579 int pass_end = 0);
00580
00581
00582
00583
00584
00585 int advance (void);
00586
00587
00588 void dump (void) const;
00589
00590
00591
00592
00593 ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator++ (void);
00594
00595
00596 ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator++ (int);
00597
00598
00599 ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator-- (void);
00600
00601
00602 ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator-- (int);
00603
00604
00605 ACE_ALLOC_HOOK_DECLARE;
00606 };
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00621 class ACE_Map_Const_Iterator : public ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>
00622 {
00623 public:
00624
00625 ACE_Map_Const_Iterator (const ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
00626 int pass_end = 0);
00627
00628
00629
00630
00631
00632 int advance (void);
00633
00634
00635 void dump (void) const;
00636
00637
00638
00639
00640 ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator++ (void);
00641
00642
00643 ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator++ (int);
00644
00645
00646 ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator-- (void);
00647
00648
00649 ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator-- (int);
00650
00651
00652 ACE_ALLOC_HOOK_DECLARE;
00653 };
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00668 class ACE_Map_Reverse_Iterator : public ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>
00669 {
00670 public:
00671
00672 ACE_Map_Reverse_Iterator (ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
00673 int pass_end = 0);
00674
00675
00676
00677
00678
00679 int advance (void);
00680
00681
00682 void dump (void) const;
00683
00684
00685
00686
00687 ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator++ (void);
00688
00689
00690 ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator++ (int);
00691
00692
00693 ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator-- (void);
00694
00695
00696 ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator-- (int);
00697
00698
00699 ACE_ALLOC_HOOK_DECLARE;
00700 };
00701
00702 ACE_END_VERSIONED_NAMESPACE_DECL
00703
00704 #if defined (__ACE_INLINE__)
00705 #include "ace/Map_Manager.inl"
00706 #endif
00707
00708 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00709 #include "ace/Map_Manager.cpp"
00710 #endif
00711
00712 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00713 #pragma implementation ("Map_Manager.cpp")
00714 #endif
00715
00716 #include "ace/post.h"
00717
00718 #endif