~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/vm/KeyTable2Ref.hpp

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef KEY_TABLE2_REF_HPP
 
17
#define KEY_TABLE2_REF_HPP
 
18
 
 
19
#include "KeyTable2.hpp"
 
20
 
 
21
/**
 
22
 * KeyTable2 is DLHashTable2 with hardcoded Uint32 key named "key".
 
23
 */
 
24
template <class T, class U, class V>
 
25
class KeyTable2Ref
 
26
{
 
27
  KeyTable2<U, V>& m_ref;
 
28
public:
 
29
  KeyTable2Ref(KeyTable2<U, V>& ref) :m_ref(ref) {}
 
30
  
 
31
  bool find(Ptr<T>& ptr, Uint32 key) const {
 
32
    U rec;
 
33
    rec.key = key;
 
34
    Ptr<U> tmp;
 
35
    bool ret = m_ref.find(tmp, rec);
 
36
    ptr.i = tmp.i;
 
37
    ptr.p = static_cast<T*>(tmp.p);
 
38
    return ret;
 
39
  }
 
40
  
 
41
  bool seize(Ptr<T> & ptr) {
 
42
    Ptr<U> tmp;
 
43
    bool ret = m_ref.seize(tmp);
 
44
    ptr.i = tmp.i;
 
45
    ptr.p = static_cast<T*>(tmp.p);
 
46
    return ret;
 
47
  }
 
48
  
 
49
  void add(Ptr<T> & ptr) {
 
50
    Ptr<U> tmp;
 
51
    tmp.i = ptr.i;
 
52
    tmp.p = static_cast<U*>(ptr.p);
 
53
    m_ref.add(tmp);
 
54
  }
 
55
  
 
56
  void release(Ptr<T> & ptr) {
 
57
    Ptr<U> tmp;
 
58
    tmp.i = ptr.i;
 
59
    tmp.p = static_cast<U*>(ptr.p);
 
60
    m_ref.release(tmp);
 
61
  }
 
62
};
 
63
 
 
64
#endif