summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/FaultTolerance/RolyPoly/LogStdMap.h
blob: 29a5ff2be653e8115566d7296bdfcc54beb73a69 (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
// file      : RolyPoly/LogStdMap.h
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef LOG_STD_MAP_H
#define LOG_STD_MAP_H

#include <map>

template <typename RI, typename RV>
class Log
{
public:
  typedef RI RecordIdType;
  typedef RV RecordValueType;

private:
  typedef
  std::map <RecordIdType, RecordValueType>
  Map_;

public:
  class Duplicate {};
  class NotFound {};

  void
  insert (RecordIdType const& ri, RecordValueType const& rv)
    throw (Duplicate)
  {
    if (!map_.insert (std::make_pair (ri, rv)).second)
    {
      throw Duplicate ();
    }
  }

  bool
  contains (RecordIdType const& ri) const
  {
    return map_.count (ri) != 0;
  }


  RecordValueType const&
  lookup (RecordIdType const& ri) const throw (NotFound)
  {
    typename Map_::const_iterator i = map_.find (ri);

    if (i != map_.end ()) return i->second;
    else throw NotFound ();
  }

private:
  Map_ map_;
};

#endif // LOG_STD_MAP_H