blob: 9b54d35331502b362d84951cdda91f104c667a0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// file : RolyPoly/LogACE_RB_Tree.h
// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id : $Id$
#ifndef LOG_ACE_RB_TREE_H
#define LOG_ACE_RB_TREE_H
#include <ace/RB_Tree.h>
#include <ace/Synch.h>
template <typename RI, typename RV>
class Log
{
public:
typedef RI RecordIdType;
typedef RV RecordValueType;
private:
typedef
ACE_RB_Tree <RecordIdType,
RecordValueType,
ACE_Less_Than<RecordIdType>,
ACE_Null_Mutex>
Map_;
public:
class Duplicate {};
class NotFound {};
void
insert (RecordIdType const& ri, RecordValueType const& rv)
throw (Duplicate)
{
if (map_.bind (ri, rv) != 0) throw Duplicate ();
}
bool
contains (RecordIdType const& ri) const
{
// Guess what: ACE_RB_Tree::find() is not const.
//
Map_& m = const_cast<Map_&> (map_);
RecordValueType tmp;
return m.find (ri, tmp) == 0;
}
RecordValueType const&
lookup (RecordIdType const& ri) const throw (NotFound)
{
Map_& m = const_cast<Map_&> (map_);
typename Map_::ENTRY* entry;
if (m.find (ri, entry) != 0) throw NotFound ();
return entry->item ();
}
private:
Map_ map_;
};
#endif // LOG_ACE_RB_TREE_H
|