5 #ifndef BPP_NUMERIC_PARAMETRIZABLECOLLECTION_H 6 #define BPP_NUMERIC_PARAMETRIZABLECOLLECTION_H 62 vChanged_(set.vChanged_)
66 for (
const auto& it:
set.objectsSet_)
68 objectsSet_[it.first] = std::shared_ptr<N>(it.second->clone());
77 vChanged_ =
set.vChanged_;
81 for (
const auto& it:
set.objectsSet_)
83 objectsSet_[it.first] = std::shared_ptr<N>(it.second->clone());
118 std::vector<size_t> vCh;
120 std::map<size_t, ParameterList > mNumPl;
122 for (
size_t i = 0; i < parameters.
size(); i++)
124 std::string n = parameters[i].getName();
125 size_t t = n.rfind(
"_");
126 if (t == std::string::npos)
128 size_t num = (size_t)atoi(n.substr(t + 1).c_str());
129 mNumPl[num].addParameter(
Parameter(n.substr(0, t), parameters[i].getValue()));
132 std::map<size_t, ParameterList >::iterator it;
135 for (it = mNumPl.begin(); it != mNumPl.end(); it++)
137 if (
hasObject(it->first) && objectsSet_[it->first]->matchParametersValues(it->second))
138 vChanged_.push_back(it->first);
165 return objectsSet_.find(objectIndex) != objectsSet_.end();
176 for (
const auto key : objectsSet_)
178 if (key.second ==
object)
194 for (
const auto key:objectsSet_)
196 if (key.second ==
object)
200 throw Exception(
"ParametrizableCollection::getFirstKey: Unknown object");
208 const std::vector<size_t>
keys()
const 210 std::vector<size_t> vkeys;
212 for (
const auto& it:objectsSet_)
214 vkeys.push_back(it.first);
226 std::shared_ptr<const N>
operator[](
size_t objectIndex)
const 228 const auto it = objectsSet_.find(objectIndex);
229 if (it == objectsSet_.end())
232 return std::dynamic_pointer_cast<
const N>(it->second);
237 auto it = objectsSet_.find(objectIndex);
238 if (it == objectsSet_.end())
254 const auto it = objectsSet_.find(objectIndex);
256 if (it != objectsSet_.end())
258 if (std::dynamic_pointer_cast<const ParameterAliasable>(it->second) != NULL)
259 pl = std::dynamic_pointer_cast<const ParameterAliasable>(it->second)->getIndependentParameters();
261 pl = it->second->getParameters();
263 for (
size_t i = 0; i < pl.
size(); i++)
284 void addObject(std::shared_ptr<N>
object,
size_t objectIndex)
286 auto it = objectsSet_.find(objectIndex);
287 if (it != objectsSet_.end())
288 throw BadIntegerException(
"ParametrizableCollection<N>::addObject. Object objectIndex already used", (
int)objectIndex);
290 objectsSet_[objectIndex] = object;
293 std::vector<std::string> nplm;
294 nplm =
object->getParameters().getParameterNames();
296 for (
const auto& pname:nplm)
303 if (std::dynamic_pointer_cast<ParameterAliasable>(
object))
306 for (
const auto& name:nplm)
308 std::vector<std::string> va = ppa->
getAlias(name);
309 for (
const auto& alias:va)
326 if (objectsSet_.find(objectIndex) == objectsSet_.end())
327 throw BadIntegerException(
"ParametrizableCollection<N>::removeObject. None Object at this objectIndex", (
int)objectIndex);
329 auto pm = objectsSet_[objectIndex];
330 objectsSet_.erase(objectIndex);
336 for (
size_t i = pl.
size(); i > 0; i--)
338 std::string pn = pl[i - 1].getName();
340 size_t pu = pn.rfind(
"_");
341 int nm = atoi(pn.substr(pu + 1).c_str());
342 if (nm == (
int)objectIndex)
344 std::vector<std::string> alpn =
getAlias(pn);
345 for (
unsigned j = 0; j < alpn.size(); j++)
370 std::shared_ptr<N>
replaceObject(std::shared_ptr<N>
object,
size_t objectIndex)
378 #endif // BPP_NUMERIC_PARAMETRIZABLECOLLECTION_H std::shared_ptr< N > operator[](size_t objectIndex)
bool hasObject(std::shared_ptr< N > object) const
Says if there is an object in the map.
Plain collection of parametrizable objects.
virtual std::vector< std::string > getAlias(const std::string &name) const
std::shared_ptr< const N > operator[](size_t objectIndex) const
Get one object from the set knowing its index.
std::vector< size_t > vChanged_
A vector of the numbers of objects that have changed during the last fireParameterChanged.
Extend the Parametrizable interface with support for parameter aliases.
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 clear()
Resets all the information contained in this object.
Number exception: integers.
virtual std::vector< std::string > getAlias(const std::string &name) const =0
~ParametrizableCollection()
void unaliasParameters(const std::string &p1, const std::string &p2)
Detach two parameters previously set as 'aliased'.
ParametrizableCollection< N > & operator=(const ParametrizableCollection< N > &set)
This class is designed to facilitate the manipulation of parameters.
void addParameter_(Parameter *parameter)
ParametrizableCollection< N > * clone() const
Create a copy of this object and send a pointer to it.
void deleteParameter_(size_t index)
The parameter list object.
void addObject(std::shared_ptr< N > object, size_t objectIndex)
Add a new object to the set with a given number.
bool hasObject(size_t objectIndex) const
Says if there is a object with a given index.
A partial implementation of the Parametrizable interface.
std::map< size_t, std::shared_ptr< N > > objectsSet_
Contains all objects used.
std::vector< size_t > hasChanged() const
std::shared_ptr< N > removeObject(size_t objectIndex)
Remove a object from the set, and all corresponding parameters.
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
void fireParameterChanged(const ParameterList ¶meters)
virtual void setName(const std::string &name)
Set the name of this parameter.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
const std::vector< size_t > keys() const
Returns the keys of the set.
size_t getNumberOfObjects() const
ParametrizableCollection()
Create an empty object set.
void aliasParameters(const std::string &p1, const std::string &p2)
alias the parameters.
ParametrizableCollection(const ParametrizableCollection< N > &set)
size_t getFirstKey(std::shared_ptr< N > object) const
Return the first key mapping an object in the map.
std::string toString(T t)
General template method to convert to a string.
const ParameterList & getParameters() const override
Get all parameters available.
ParameterList getParametersForObject(size_t objectIndex) const
Get the paramters of the Collection corresponding to an object from the set knowing its index...