summaryrefslogtreecommitdiffstats
path: root/src/librados/ListObjectImpl.h
blob: 7396c12108d0c9c0961ac63d419e20273b14b228 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2014 David Zafman <dzafman@redhat.com>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#ifndef CEPH_LIBRADOS_LISTOBJECTIMPL_H
#define CEPH_LIBRADOS_LISTOBJECTIMPL_H

#include <string>
#include <include/rados/librados.hpp>

#include "include/cmp.h"

namespace librados {
struct ListObjectImpl {
  std::string nspace;
  std::string oid;
  std::string locator;

  ListObjectImpl() {}
  ListObjectImpl(std::string n, std::string o, std::string l):
      nspace(n), oid(o), locator(l) {}

  const std::string& get_nspace() const { return nspace; }
  const std::string& get_oid() const { return oid; }
  const std::string& get_locator() const { return locator; }
};
WRITE_EQ_OPERATORS_3(ListObjectImpl, nspace, oid, locator)
WRITE_CMP_OPERATORS_3(ListObjectImpl, nspace, oid, locator)
inline std::ostream& operator<<(std::ostream& out, const struct ListObjectImpl& lop) {
  out << (lop.nspace.size() ? lop.nspace + "/" : "") << lop.oid
      << (lop.locator.size() ? "@" + lop.locator : "");
  return out;
}

class NObjectIteratorImpl {
  public:
    NObjectIteratorImpl() {}
    ~NObjectIteratorImpl();
    NObjectIteratorImpl(const NObjectIteratorImpl &rhs);
    NObjectIteratorImpl& operator=(const NObjectIteratorImpl& rhs);

    bool operator==(const NObjectIteratorImpl& rhs) const;
    bool operator!=(const NObjectIteratorImpl& rhs) const;
    const ListObject& operator*() const;
    const ListObject* operator->() const;
    NObjectIteratorImpl &operator++(); // Preincrement
    NObjectIteratorImpl operator++(int); // Postincrement
    const ListObject *get_listobjectp() { return &cur_obj; }

    /// get current hash position of the iterator, rounded to the current pg
    uint32_t get_pg_hash_position() const;

    /// move the iterator to a given hash position.  this may (will!) be rounded to the nearest pg.
    uint32_t seek(uint32_t pos);

    /// move the iterator to a given cursor position
    uint32_t seek(const librados::ObjectCursor& cursor);

    /// get current cursor position
    librados::ObjectCursor get_cursor();

    void set_filter(const bufferlist &bl);

    NObjectIteratorImpl(ObjListCtx *ctx_);
    void get_next();
    std::shared_ptr < ObjListCtx > ctx;
    ListObject cur_obj;
};

}
#endif