mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 05:48:25 +08:00
add class SVector like C sharp List
This commit is contained in:
53
Common/cppcf/svector.cpp
Normal file
53
Common/cppcf/svector.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "svector.h"
|
||||
|
||||
template<class T>
|
||||
SVector<T>::SVector(size_t reserve, T initValue) : array(reserve, initValue)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
SVector<T>::SVector(bool needInit)
|
||||
{
|
||||
isInit = needInit;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
SVector<T>::SVector(size_t reserve) : array(reserve)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> SVector<T>::operator[](size_t pos) const
|
||||
{
|
||||
if (!isInit || array.size() <= pos)
|
||||
return {};
|
||||
|
||||
return array[pos];
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void SVector<T>::push_back(T &&value)
|
||||
{
|
||||
isInit = true;
|
||||
array.push_back(std::shared_ptr<T>(value));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> SVector<T>::back() const
|
||||
{
|
||||
if (!isInit || array.empty())
|
||||
return {};
|
||||
|
||||
return array.back();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> SVector<T>::front() const
|
||||
{
|
||||
if (!isInit || array.empty())
|
||||
return {};
|
||||
|
||||
return array.front();
|
||||
}
|
||||
Reference in New Issue
Block a user