19 const std::out_of_range& e,
const std::size_t& key,
const std::vector<std::any>& data
42 TokenList(
const std::vector<std::any>& data,
size_t nextIndex = 0);
48 TokenList(
const std::initializer_list<std::any>& initList);
66 [[nodiscard]]
bool empty()
const;
74 template<
typename ReturnType>
77 ReturnType ret {get<ReturnType>(0)};
78 data_.erase(data_.begin());
86 [[nodiscard]]
size_t size()
const;
92 void reset()
const { nextIndex_ = 0; }
102 template<
typename ReturnType>
103 [[nodiscard]] ReturnType&
get(
const size_t& idx)
107 return std::any_cast<ReturnType&>(data_.at(idx));
109 catch (
const std::bad_any_cast& e)
111 logBadAnyCast<ReturnType>(e, idx, data_);
114 catch (
const std::out_of_range& e)
128 template<
typename ReturnType>
131 ReturnType& retValue = get<ReturnType&>(nextIndex_);
144 template<
typename ReturnType>
145 [[nodiscard]]
const ReturnType&
get(
const size_t& idx)
const
149 return std::any_cast<const ReturnType&>(data_.at(idx));
151 catch (
const std::bad_any_cast& e)
153 logBadAnyCast<ReturnType>(e, idx, data_);
156 catch (
const std::out_of_range& e)
170 template<
typename ReturnType>
173 const ReturnType& retValue = get<ReturnType>(nextIndex_);
184 template<
typename ReturnType>
187 return nextIndex_ < data_.size() && data_[nextIndex_].type() ==
typeid(ReturnType);
197 [[nodiscard]] std::vector<std::any>&
tokens();
202 std::vector<std::any> data_;
203 mutable size_t nextIndex_;
A class representing a list of tokens.
bool empty() const
Checks if the token list is empty.
size_t size() const
Retrieves the size of the token list.
ReturnType popFront()
Removes first entry of TokenList and returns it.
ReturnType & get(const size_t &idx)
Retrieves the value associated with the given index, casting it to the specified type.
std::vector< std::any > & tokens()
const ReturnType & get(const size_t &idx) const
Retrieves the value associated with the given index, casting it to the specified type.
std::any & operator[](const size_t &idx)
Retrieves the value associated with the given index.
void reset() const
Rewind the read cursor used by next<>() so the list can be iterated again from the beginning.
void insert(const std::any &value)
Inserts a value into the token list.
ReturnType & next()
Retrieves the value associated with the nextIndex, casting it to the specified type.
TokenList(const TokenList &)
TokenList(const std::initializer_list< std::any > &initList)
Construct a TokenList object from an initializer list of std::any.
void remove(size_t index)
Removes a value from the token list based on the specified index.
const ReturnType & next() const
Retrieves the value associated with the nextIndex, casting it to the specified type.
bool peekIs() const
Checks whether the next token (the one a subsequent next() would return) holds a value of the given t...
TokenList(const std::vector< std::any > &data, size_t nextIndex=0)
Construct a TokenList object from a vector of std::any.
Integer types used throughout NeoN.
void logOutRange(const std::out_of_range &e, const std::string &key, const std::unordered_map< std::string, std::any > &data)
#define NEON_TYPE_VISIBLE