Rise
The Vieneo Province
Loading...
Searching...
No Matches
ControlArray.h
Go to the documentation of this file.
1#pragma once
2#include <Windows.h>
3#include <algorithm>
4#include <vector>
5#include <new>
6
7// The controls expose stable integer indices; ownership remains with their
8// dialog/resource manager just as it does for the game's other UI objects.
9template<class T> class ControlArray
10{
11public:
12 int GetSize() const {return int(values.size());}
13 T& GetAt(int index){return values.at(size_t(index));}
14 const T& GetAt(int index) const {return values.at(size_t(index));}
15 T& operator[](int index){return GetAt(index);}
16 const T& operator[](int index) const {return GetAt(index);}
17 T* GetData(){return values.data();}
18 const T* GetData() const {return values.data();}
19 HRESULT Add(const T& value){try{values.push_back(value);return S_OK;}catch(const std::bad_alloc&){return E_OUTOFMEMORY;}}
20 HRESULT SetSize(int count){if(count<0)return E_INVALIDARG;try{values.resize(size_t(count));return S_OK;}catch(const std::bad_alloc&){return E_OUTOFMEMORY;}}
21 HRESULT SetAt(int index,const T& value){if(index<0 || index>=GetSize())return E_INVALIDARG;values[size_t(index)]=value;return S_OK;}
22 HRESULT Insert(int index,const T& value){if(index<0 || index>GetSize())return E_INVALIDARG;try{values.insert(values.begin()+index,value);return S_OK;}catch(const std::bad_alloc&){return E_OUTOFMEMORY;}}
23 HRESULT Remove(int index){if(index<0 || index>=GetSize())return E_INVALIDARG;values.erase(values.begin()+index);return S_OK;}
24 void RemoveAll(){values.clear();}
25 bool Contains(const T& value) const {return IndexOf(value)>=0;}
26 int IndexOf(const T& value) const {const auto found=std::find(values.begin(),values.end(),value);return found==values.end() ? -1 : int(found-values.begin());}
27private:
28 std::vector<T> values;
29};
SCRIPT_CONTROL SCRIPT_STATE const void int
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
void RemoveAll()
T & GetAt(int index)
bool Contains(const T &value) const
const T * GetData() const
HRESULT SetAt(int index, const T &value)
int GetSize() const
const T & operator[](int index) const
const T & GetAt(int index) const
T & operator[](int index)
std::vector< T > values
HRESULT SetSize(int count)
HRESULT Add(const T &value)
HRESULT Remove(int index)
HRESULT Insert(int index, const T &value)
int IndexOf(const T &value) const