logace_rb_tree.h

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C头文件 代码 · 共 67 行

H
67
字号
// file      : RolyPoly/LogACE_RB_Tree.h
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : LogACE_RB_Tree.h,v 1.2 2003/12/22 01:44:37 wilson_d Exp

#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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?