41 #ifndef BPP_NUMERIC_PARAMETRIZABLECOLLECTION_H
42 #define BPP_NUMERIC_PARAMETRIZABLECOLLECTION_H
104 objectsSet_[it.first] = std::shared_ptr<N>(it.second->clone());
119 objectsSet_[it.first] = std::shared_ptr<N>(it.second->clone());
154 std::vector<size_t> vCh;
156 std::map<size_t, ParameterList > mNumPl;
158 for (
size_t i = 0; i < parameters.
size(); i++)
160 std::string n = parameters[i].getName();
161 size_t t = n.rfind(
"_");
162 if (t == std::string::npos)
164 size_t num = (size_t)atoi(n.substr(t + 1).c_str());
168 std::map<size_t, ParameterList >::iterator it;
171 for (it = mNumPl.begin(); it != mNumPl.end(); it++)
214 if (key.second ==
object)
232 if (key.second ==
object)
236 throw Exception(
"ParametrizableCollection::getFirstKey: Unknown object");
244 const std::vector<size_t>
keys()
const
246 std::vector<size_t> vkeys;
250 vkeys.push_back(it.first);
262 std::shared_ptr<const N>
operator[](
size_t objectIndex)
const
268 return std::dynamic_pointer_cast<const N>(it->second);
294 if (std::dynamic_pointer_cast<const ParameterAliasable>(it->second) != NULL)
295 pl = std::dynamic_pointer_cast<const ParameterAliasable>(it->second)->getIndependentParameters();
297 pl = it->second->getParameters();
299 for (
size_t i = 0; i < pl.
size(); i++)
320 void addObject(std::shared_ptr<N>
object,
size_t objectIndex)
324 throw BadIntegerException(
"ParametrizableCollection<N>::addObject. Object objectIndex already used", (
int)objectIndex);
329 std::vector<std::string> nplm;
330 nplm =
object->getParameters().getParameterNames();
332 for (
const auto& pname:nplm)
339 if (std::dynamic_pointer_cast<ParameterAliasable>(
object))
341 auto ppa = std::dynamic_pointer_cast<ParameterAliasable>(
object);
342 for (
const auto& name:nplm)
344 std::vector<std::string> va = ppa->getAlias(name);
345 for (
const auto& alias:va)
363 throw BadIntegerException(
"ParametrizableCollection<N>::removeObject. None Object at this objectIndex", (
int)objectIndex);
372 for (
size_t i = pl.
size(); i > 0; i--)
374 std::string pn = pl[i - 1].getName();
376 size_t pu = pn.rfind(
"_");
377 int nm = atoi(pn.substr(pu + 1).c_str());
378 if (nm == (
int)objectIndex)
380 std::vector<std::string> alpn =
getAlias(pn);
381 for (
unsigned j = 0; j < alpn.size(); j++)
406 std::shared_ptr<N>
replaceObject(std::shared_ptr<N>
object,
size_t objectIndex)
A partial implementation of the Parametrizable interface.
virtual std::vector< std::string > getAlias(const std::string &name) const
void unaliasParameters(const std::string &p1, const std::string &p2)
Detach two parameters previously set as 'aliased'.
void deleteParameter_(size_t index)
void addParameter_(Parameter *parameter)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
void aliasParameters(const std::string &p1, const std::string &p2)
alias the parameters.
const ParameterList & getParameters() const
Get all parameters available.
Number exception: integers.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
The parameter list object.
virtual void addParameter(const Parameter ¶m)
Add a new parameter at the end of the list.
This class is designed to facilitate the manipulation of parameters.
virtual void setName(const std::string &name)
Set the name of this parameter.
Plain collection of parametrizable objects.
ParametrizableCollection()
Create an empty object set.
ParametrizableCollection< N > & operator=(const ParametrizableCollection< N > &set)
size_t getFirstKey(std::shared_ptr< N > object) const
Return the first key mapping an object in the map.
std::map< size_t, std::shared_ptr< N > > objectsSet_
Contains all objects used.
ParameterList getParametersForObject(size_t objectIndex) const
Get the paramters of the Collection corresponding to an object from the set knowing its index.
const std::vector< size_t > keys() const
Returns the keys of the set.
ParametrizableCollection(const ParametrizableCollection< N > &set)
ParametrizableCollection< N > * clone() const
Create a copy of this object and send a pointer to it.
bool hasObject(std::shared_ptr< N > object) const
Says if there is an object in the map.
void fireParameterChanged(const ParameterList ¶meters)
std::shared_ptr< N > replaceObject(std::shared_ptr< N > object, size_t objectIndex)
Replace a object in the set, and returns the replaced one.
void addObject(std::shared_ptr< N > object, size_t objectIndex)
Add a new object to the set with a given number.
std::shared_ptr< N > removeObject(size_t objectIndex)
Remove a object from the set, and all corresponding parameters.
std::shared_ptr< N > operator[](size_t objectIndex)
std::shared_ptr< const N > operator[](size_t objectIndex) const
Get one object from the set knowing its index.
size_t getNumberOfObjects() const
bool hasObject(size_t objectIndex) const
Says if there is a object with a given index.
~ParametrizableCollection()
void clear()
Resets all the information contained in this object.
std::vector< size_t > hasChanged() const
std::vector< size_t > vChanged_
A vector of the numbers of objects that have changed during the last fireParameterChanged.
std::string toString(T t)
General template method to convert to a string.