feat: encoding accessor in foundry & less constrained forge setup
Allow forge setup to be called on nullptr and have an empty constructor setup. Useful to build up forge vectors in one pass instead of add/setup loops.
This commit is contained in:
parent
13d62d0445
commit
5a64a1755a
2 changed files with 18 additions and 2 deletions
|
|
@ -62,6 +62,11 @@ class eoAlgoFoundry : public eoAlgo<EOT>
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<size_t> encoding() const
|
||||||
|
{
|
||||||
|
return _encoding;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const size_t _size;
|
const size_t _size;
|
||||||
std::vector<size_t> _encoding;
|
std::vector<size_t> _encoding;
|
||||||
|
|
|
||||||
|
|
@ -265,12 +265,23 @@ class eoForgeVector : public std::vector<eoForgeInterface<Itf>*>
|
||||||
template<class Op, typename... Args>
|
template<class Op, typename... Args>
|
||||||
void setup(size_t index, Args... args)
|
void setup(size_t index, Args... args)
|
||||||
{
|
{
|
||||||
assert(this->at(index) != nullptr);
|
assert(index < this->size());
|
||||||
delete this->at(index);
|
delete this->at(index); // Silent on nullptr.
|
||||||
auto pfo = new eoForgeOperator<Itf,Op,Args...>(args...);
|
auto pfo = new eoForgeOperator<Itf,Op,Args...>(args...);
|
||||||
this->at(index) = pfo;
|
this->at(index) = pfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Specialization for empty constructors.
|
||||||
|
*/
|
||||||
|
template<class Op>
|
||||||
|
void setup(size_t index)
|
||||||
|
{
|
||||||
|
assert(index < this->size());
|
||||||
|
delete this->at(index);
|
||||||
|
auto pfo = new eoForgeOperator<Itf,Op>;
|
||||||
|
this->at(index) = pfo;
|
||||||
|
}
|
||||||
|
|
||||||
/** Instanciate the operator managed at the given index.
|
/** Instanciate the operator managed at the given index.
|
||||||
*/
|
*/
|
||||||
Itf& instanciate(size_t index)
|
Itf& instanciate(size_t index)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue