📄 orvector.hpp
字号:
{
it->~T();
memmove(it, it+1, (_Last - it - 1) * sizeof(T));
_Last--;
return it;
}
inline iterator erase(iterator first, iterator last)
{
if (first != last) {
_Destroy(first, last);
if (last != _Last)
memmove(first, last, (_Last - last - 1) * sizeof(T));
_Last -= last - first;
}
return first;
}
inline iterator insert(iterator p, const T &X = T())
{
const int ind = p - _First;
insert(p, 1, X);
return _First + ind;
}
inline void insert(iterator p, const int &n, const T &X)
{
if (_End - _Last < n) {
const int pi = p - _First;
_Resize(size() + n);
p = _First + pi;
}
iterator e = p + n;
if (p != _Last)
memmove(e, p, (_Last - p - 1) * sizeof(T));
for(; p != e; _Set(p++, X));
_Last += n;
}
inline void insert(iterator p, iterator first, iterator last)
{
const int n = last - first;
if (_End - _Last < n) {
const int pi = p - _First;
_Resize(size() + n);
p = _First + pi;
}
iterator e = p + n;
if (p != _Last)
memmove(e, p, (_Last - p - 1) * sizeof(T));
for(; first != last; _Set(p++, *(first++)));
_Last += n;
}
inline void push_back(T const &x)
{
if (_Last == _End)
_Resize(size() + 1);
_Set(_Last++, x);
}
inline void reserve(const int n)
{ if (n >= _Last - _First)
_Resize(n);
}
inline void resize(const int n, T x = T())
{ if (n < size()) {
_Destroy(_First + n, _Last);
_Resize(n);
_Last = _First + n;
}
else {
_Resize(n);
for(iterator _nLast = _First + n; _Last != _nLast; _Set(_Last++, x));
}
}
inline void _Destroy(const iterator first, const iterator last)
{ for(iterator p = first; p != last; p++)
p->~T();
}
inline void _Resize(const int &n)
{
int sze = _RoundUpSize(n);
if (!_First) {
_Last = _First = (iterator)malloc(sze * sizeof(T));
_End = _First + sze;
}
else if (_End - _First != sze) {
int osize = size();
_First = (iterator)realloc(_First, sze * sizeof(T));
_Last = _First + osize;
_End = _First + sze;
}
}
};
/*ORANGE_EXTERN template class ORANGE_API TOrangeVector<bool, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<int, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<long, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<float, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<int, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<pair<int, float>, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<pair<float, float>, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<double, false>;
ORANGE_EXTERN template class ORANGE_API TOrangeVector<string, false>;
*/
#define TBoolList TOrangeVector<bool, false>
#define TIntList TOrangeVector<int, false>
#define TLongList TOrangeVector<long, false>
#define TFloatList TOrangeVector<float, false>
#define TIntFloatList TOrangeVector<pair<int, float>, false >
#define TFloatFloatList TOrangeVector<pair<float, float>, false >
#define TDoubleList TOrangeVector<double, false>
#define TStringList TOrangeVector<string, false>
#define TFloatListList TOrangeVector<PFloatList>
VWRAPPER(BoolList)
VWRAPPER(IntList)
VWRAPPER(LongList)
VWRAPPER(FloatList)
VWRAPPER(IntFloatList)
VWRAPPER(FloatFloatList)
VWRAPPER(FloatListList)
VWRAPPER(DoubleList)
VWRAPPER(StringList)
WRAPPER(Variable)
#include "values.hpp"
#include "vars.hpp"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4275)
#endif
/* This is to fool pyprops
#define TValueList _TOrangeVector<float>
*/
#define TVarList TOrangeVector<PVariable>
VWRAPPER(VarList)
#define __REGISTER_NO_PYPROPS_CLASS __REGISTER_CLASS
class ORANGE_API TAttributedFloatList : public TOrangeVector<float, false>
{
public:
__REGISTER_NO_PYPROPS_CLASS
PVarList attributes;
inline TAttributedFloatList()
{}
inline TAttributedFloatList(PVarList vlist)
: attributes(vlist)
{}
inline TAttributedFloatList(PVarList vlist, const int &i_N, const float &f = 0.0)
: TOrangeVector<float, false>(i_N, f),
attributes(vlist)
{}
inline TAttributedFloatList(PVarList vlist, const vector<float> &i_X)
: TOrangeVector<float,false>(i_X),
attributes(vlist)
{}
};
class ORANGE_API TAttributedBoolList : public TOrangeVector<bool, false>
{
public:
__REGISTER_NO_PYPROPS_CLASS
PVarList attributes;
inline TAttributedBoolList()
{}
inline TAttributedBoolList(PVarList vlist)
: attributes(vlist)
{}
inline TAttributedBoolList(PVarList vlist, const int &i_N, const bool b= false)
: TOrangeVector<bool, false>(i_N, b),
attributes(vlist)
{}
inline TAttributedBoolList(PVarList vlist, const vector<bool> &i_X)
: TOrangeVector<bool, false>(i_X),
attributes(vlist)
{}
};
class ORANGE_API TValueList : public TOrangeVector<TValue, false>
{
public:
__REGISTER_CLASS
PVariable variable; //P the variable to which the list applies
inline TValueList(PVariable var = PVariable())
: TOrangeVector<TValue, false>(),
variable(var)
{}
inline TValueList(const int &N, const TValue &V = TValue(), PVariable var = PVariable())
: TOrangeVector<TValue, false>(N, V),
variable(var)
{}
inline TValueList(const TOrangeVector<TValue, false> &i_X, PVariable var = PVariable())
: TOrangeVector<TValue, false>(i_X),
variable(var)
{}
inline TValueList(const TValueList &other)
: TOrangeVector<TValue, false>(other),
variable(other.variable)
{}
int traverse(visitproc visit, void *arg) const
{
TRAVERSE(TOrange::traverse);
for(TValue *p = _First; p != _Last; p++)
if (p->svalV)
PVISIT(p->svalV);
return 0;
}
int dropReferences()
{ DROPREFERENCES(TOrange::dropReferences);
return 0;
}
};
WRAPPER(ValueList)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
/* This is to fool pyprops.py
#define TAttributedFloatList _TOrangeVector<float>
#define TAttributedBoolList _TOrangeVector<bool>
*/
WRAPPER(AttributedFloatList)
WRAPPER(AttributedBoolList)
#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable : 4290)
template class ORANGE_API std::vector<int>;
template class ORANGE_API std::vector<float>;
#pragma warning (pop)
#endif
/* These are defined as classes, not templates, so that
class TIntIntPair {
public:
int first, second;
TIntIntPair(const int &f, const int &s)
: first(f),
second(s)
{}
};
class TIntIntPair {
public:
int first, second;
TIntIntPair(const int &f, const int &s)
: first(f),
second(s)
{}
};
class TIntIntPair {
public:
int first, second;
TIntIntPair(const int &f, const int &s)
: first(f),
second(s)
{}
};
class TIntIntPair {
public:
int first, second;
TIntIntPair(const int &f, const int &s)
: first(f),
second(s)
{}
};
*/
#ifdef _MSC_VER
template class ORANGE_API std::vector<pair<int, int> >;
template class ORANGE_API std::vector<int>;
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -