~mathiaz/+junk/ceph-new-pkg-review

« back to all changes in this revision

Viewing changes to src/include/bitmapper.h

  • Committer: Mathias Gug
  • Date: 2010-07-29 03:10:42 UTC
  • Revision ID: mathias.gug@canonical.com-20100729031042-n9n8kky962qb4onb
Import ceph_0.21-0ubuntu1 from https://launchpad.net/~clint-fewbar/+archive/ceph/+packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
 
2
// vim: ts=8 sw=2 smarttab
 
3
/*
 
4
 * Ceph - scalable distributed file system
 
5
 *
 
6
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 
7
 *
 
8
 * This is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License version 2.1, as published by the Free Software 
 
11
 * Foundation.  See file COPYING.
 
12
 * 
 
13
 */
 
14
 
 
15
#ifndef CEPH_BITMAPPER_H
 
16
#define CEPH_BITMAPPER_H
 
17
 
 
18
class bitmapper {
 
19
  char *_data;
 
20
  int _len;
 
21
 
 
22
 public:
 
23
  bitmapper() : _data(0), _len(0) { }
 
24
  bitmapper(char *data, int len) : _data(data), _len(len) { }
 
25
 
 
26
  void set_data(char *data, int len) { _data = data; _len = len; }
 
27
 
 
28
  int bytes() const { return _len; }
 
29
  int bits() const { return _len * 8; }
 
30
 
 
31
  bool operator[](int b) const {
 
32
    return get(b);
 
33
  }
 
34
  bool get(int b) const {
 
35
    return _data[b >> 3] & (1 << (b&7));
 
36
  }
 
37
  void set(int b) {
 
38
    _data[b >> 3] |= 1 << (b&7);
 
39
  }
 
40
  void clear(int b) {
 
41
    _data[b >> 3] &= ~(1 << (b&7));
 
42
  }
 
43
  void toggle(int b) {
 
44
    _data[b >> 3] ^= 1 << (b&7);
 
45
  }
 
46
};
 
47
 
 
48
#endif