libUTL++
RandIt.h
1 #pragma once
2 
4 
5 #include <libutl/BidIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
23 
25 class RandIt : public BidIt
26 {
29 
30 public:
31  virtual Object* get() const = 0;
32 
38  virtual Object* get(size_t offset) const = 0;
39 
41  virtual size_t offset() const = 0;
42 
44  virtual void seek(size_t offset) = 0;
45 
46  virtual void set(const Object* object) = 0;
47 
56  virtual void set(size_t offset, const Object* object) = 0;
57 
59  virtual size_t size() const = 0;
60 
68  virtual size_t
69  subtract(const RandIt& it) const
70  {
71  return (offset() - it.offset());
72  }
73 
75  size_t operator-(const RandIt& it) const
76  {
77  return subtract(it);
78  }
79 
81  Object* operator[](size_t offset) const
82  {
83  return get(offset);
84  }
85 
86 public:
87  // for STL
88  typedef Object* value_type;
89  typedef Object*& reference;
90  typedef Object** pointer;
91  typedef std::random_access_iterator_tag iterator_category;
92  typedef std::ptrdiff_t difference_type;
93 };
94 
96 
97 UTL_NS_END;
98 
100 
101 #include <libutl/TRandIt.h>
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
size_t operator-(const RandIt &it) const
Provides a user-friendly interface to subtract().
Definition: RandIt.h:75
Subtraction function.
Random-access iterator abstraction.
Definition: RandIt.h:25
#define UTL_CLASS_DECL_ABC(DC, BC)
Declaration of standard UTL++ functionality for an abstract base class (ABC).
Definition: macros.h:650
virtual size_t subtract(const RandIt &it) const
Determine the distance between self and another random-access iterator for the same sequence...
Definition: RandIt.h:69
Bi-directional iterator abstraction.
Definition: BidIt.h:25
Object * operator[](size_t offset) const
Provides a user-friendly interface to get().
Definition: RandIt.h:81
virtual size_t offset() const =0
Get the current offset.
Root of UTL++ class hierarchy.
Definition: Object.h:52