39 lines
1.5 KiB
C++
39 lines
1.5 KiB
C++
// CArray<T, ARG_T> wrapping std::vector with MFC's method names.
|
|
#pragma once
|
|
#include "afx.h"
|
|
#include <vector>
|
|
#include <cstddef>
|
|
|
|
template<class T, class ARG_T = const T&>
|
|
class CArray {
|
|
std::vector<T> v;
|
|
public:
|
|
CArray() = default;
|
|
|
|
int GetSize() const { return (int)v.size(); }
|
|
int GetCount() const { return (int)v.size(); }
|
|
bool IsEmpty() const { return v.empty(); }
|
|
int GetUpperBound() const { return (int)v.size() - 1; }
|
|
|
|
void SetSize(int n, int /*growBy*/ = -1) { v.resize((size_t)n); }
|
|
void RemoveAll() { v.clear(); }
|
|
void RemoveAt(int i, int n = 1) { v.erase(v.begin() + i, v.begin() + i + n); }
|
|
|
|
int Add(ARG_T x) { v.push_back(x); return (int)v.size() - 1; }
|
|
void InsertAt(int i, ARG_T x, int n = 1) { v.insert(v.begin() + i, (size_t)n, x); }
|
|
|
|
T GetAt(int i) const { return v[(size_t)i]; }
|
|
void SetAt(int i, ARG_T x) { v[(size_t)i] = x; }
|
|
T& ElementAt(int i) { return v[(size_t)i]; }
|
|
void SetAtGrow(int i, ARG_T x) { if ((size_t)i >= v.size()) v.resize((size_t)i + 1); v[(size_t)i] = x; }
|
|
|
|
T* GetData() { return v.data(); }
|
|
const T* GetData() const { return v.data(); }
|
|
|
|
T& operator[](int i) { return v[(size_t)i]; }
|
|
const T& operator[](int i) const { return v[(size_t)i]; }
|
|
|
|
void Copy(const CArray& src) { v = src.v; }
|
|
int Append(const CArray& src) { int s = (int)v.size(); v.insert(v.end(), src.v.begin(), src.v.end()); return s; }
|
|
};
|