/usr/include/dlib/interfaces/enumerable.h is in libdlib-dev 18.18-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | // Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ENUMERABLe_INTERFACE_
#define DLIB_ENUMERABLe_INTERFACE_
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename T
>
class enumerable
{
/*!
POINTERS AND REFERENCES TO INTERNAL DATA
- if (at_start()) then
- all pointers and references to data returned via element() are
invalid.
- calling move_next() or reset() invalidates pointers and references to
data returned via element() and only data returned via element().
- calling at_start(), current_element_valid(), size(), or element()
does NOT invalidate pointers or references to any internal data.
INITIAL VALUE
current_element_valid() == false
at_start() == true
WHAT THIS OBJECT REPRESENTS
This object represent an interface for iterating through the
elements in a container. It starts out one before the first element
in the container.
EXAMPLE: The following loops though all elements in the container
and prints them to cout.
container.reset();
while(container.move_next()) {
cout << container.element();
}
!*/
public:
typedef T type;
inline virtual ~enumerable(
) = 0;
virtual bool at_start (
) const = 0;
/*!
ensures
- returns true if *this represents one position before the first element
in the container (this would also make the current element invalid)
else returns false
!*/
virtual void reset (
) const = 0;
/*!
ensures
- #current_element_valid() == false
- #at_start() == true
!*/
virtual bool current_element_valid (
) const = 0;
/*!
ensures
- returns true if we are currently at a valid element else
returns false
!*/
virtual const T& element (
) const = 0;
/*!
requires
- current_element_valid() == true
ensures
- returns a const reference to the current element
!*/
virtual T& element (
) = 0;
/*!
requires
- current_element_valid() == true
ensures
- returns a non-const reference to the current element
!*/
virtual bool move_next (
) const = 0;
/*!
ensures
- moves to the next element. i.e. #element() will now
return the next element in the container
- the return value will be equal to #current_element_valid()
- #at_start() == false
- returns true if there is another element
- returns false if there are no more elements in the container
!*/
virtual unsigned long size (
) const = 0;
/*!
ensures
- returns the number of elements in *this
!*/
protected:
// restricted functions
enumerable& operator=(const enumerable&) {return *this;} // no assignment operator
};
// destructor does nothing
template <typename T>
enumerable<T>::~enumerable() {}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ENUMERABLe_INTERFACE_
|