/usr/include/bobcat/readlinehistory is in libbobcat-dev 2.20.01-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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | #ifndef INCLUDED_BOBCAT_READLINEHISTORY_
#define INCLUDED_BOBCAT_READLINEHISTORY_
#include <iterator>
#include <string>
#include <readline/history.h>
namespace FBB
{
class ReadLineHistory;
std::ostream &operator<<(std::ostream &out,
ReadLineHistory const &history);
std::istream &operator>>(std::istream &out, ReadLineHistory &history);
class ReadLineHistory
{
friend std::ostream &operator<<(std::ostream &out,
ReadLineHistory const &history);
friend std::istream &operator>>(std::istream &out,
ReadLineHistory &history);
static ReadLineHistory s_readLineHistory;
bool d_timestamps;
public:
class HistoryElement
{
friend class ReadLineHistory;
char const *d_line;
char const *d_timestamp;
public:
char const *line() const;
char const *timestamp() const;
private:
HistoryElement();
HistoryElement const &set(HIST_ENTRY const *element);
};
class const_iterator: public
std::iterator<std::input_iterator_tag,
HistoryElement const>
{
friend class ReadLineHistory;
friend class std::reverse_iterator<const_iterator>;
size_t d_idx;
mutable HistoryElement d_element;
public:
const_iterator &operator++();
const_iterator operator++(int);
bool operator==(const_iterator const &rhs) const;
bool operator!=(const_iterator const &rhs) const;
HistoryElement const &operator*() const;
HistoryElement const *operator->() const;
private:
const_iterator(); // inline, last element
const_iterator(size_t idx); // 2
const_iterator &operator--(); // for the reverse iter.
const_iterator operator--(int);
};
typedef std::reverse_iterator<const_iterator>
const_reverse_iterator;
ReadLineHistory(ReadLineHistory const &other) = delete;
ReadLineHistory &operator=(ReadLineHistory const &rhs) = delete;
const_iterator begin() const; // begin of the history
const_iterator end() const; // end of the history
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
ReadLineHistory &setTimestampsIO(bool useTimestamps);
size_t size() const;
size_t maxSize() const;
bool timestamps() const;
static ReadLineHistory &instance();
static ReadLineHistory &instance(bool useTimestamps);
private:
ReadLineHistory();
static void insertHistoryElement(HistoryElement const &he,
std::ostream &out);
static void insertLine(HistoryElement const &he, std::ostream &out);
static std::istream &extractTimestamps(std::istream &in);
static std::istream &extractLines(std::istream &in);
};
inline ReadLineHistory::ReadLineHistory()
{}
inline ReadLineHistory &ReadLineHistory::setTimestampsIO(bool useTimestamps)
{
d_timestamps = useTimestamps;
return *this;
}
inline ReadLineHistory::const_iterator ReadLineHistory::begin() const
{
return const_iterator(0);
}
inline ReadLineHistory::const_iterator ReadLineHistory::end() const
{
return const_iterator();
}
inline ReadLineHistory::const_reverse_iterator ReadLineHistory::rbegin() const
{
return const_reverse_iterator(end());
}
inline ReadLineHistory::const_reverse_iterator ReadLineHistory::rend() const
{
return const_reverse_iterator(begin());
}
inline ReadLineHistory &ReadLineHistory::instance()
{
return s_readLineHistory;
}
inline ReadLineHistory &ReadLineHistory::instance(bool useTimestamps)
{
return s_readLineHistory.setTimestampsIO(useTimestamps);
}
inline size_t ReadLineHistory::size() const
{
return history_length;
}
inline bool ReadLineHistory::timestamps() const
{
return d_timestamps;
}
inline size_t ReadLineHistory::maxSize() const
{
return history_max_entries;
}
// ======= HistoryElement members ============
inline ReadLineHistory::HistoryElement::HistoryElement()
:
d_line(0),
d_timestamp(0)
{}
inline char const *ReadLineHistory::HistoryElement::line() const
{
return d_line;
}
inline char const *ReadLineHistory::HistoryElement::timestamp() const
{
return d_timestamp;
}
// ======== const_iterator members
inline ReadLineHistory::const_iterator::const_iterator()
:
d_idx(history_length)
{}
inline ReadLineHistory::const_iterator::const_iterator(size_t idx)
:
d_idx(idx)
{}
inline ReadLineHistory::const_iterator
&ReadLineHistory::const_iterator::operator++()
{
++d_idx;
return *this;
}
inline ReadLineHistory::const_iterator
ReadLineHistory::const_iterator::operator++(int)
{
return const_iterator(d_idx++);
}
inline ReadLineHistory::const_iterator
&ReadLineHistory::const_iterator::operator--()
{
--d_idx;
return *this;
}
inline ReadLineHistory::const_iterator
ReadLineHistory::const_iterator::operator--(int)
{
return const_iterator(d_idx--);
}
inline bool ReadLineHistory::const_iterator::operator==(
const_iterator const &rhs) const
{
return d_idx == rhs.d_idx;
}
inline bool ReadLineHistory::const_iterator::operator!=(
const_iterator const &rhs) const
{
return not (*this == rhs);
}
inline ReadLineHistory::HistoryElement const
*ReadLineHistory::const_iterator::operator->() const
{
return &operator*();
}
} // FBB
#endif
|