charon-core  0.3.1
SlotBundle.cpp
1 #include <charon-core/SlotBundle.h>
2 #include <charon-core/Slots.h>
3 
5  const std::string &className, const std::string &name,
6  const std::string &doc)
7  :ParameteredObject(className,name,doc) {
8 
9  ParameteredObject::_addParameter< int >(
10  num_slots, "num_slots",
11  "The number of virtual slots",
12  0, "int");
13  _setDynamic(true);
14 }
15 
16 SlotBundle::~SlotBundle() {
17  //_deleteAllSlots();
18 }
19 
21 
22 }
23 
25 }
26 
28 }
29 
31  return _virtualOutputSlots.size();
32 }
33 
34 void SlotBundle::_deleteAllSlots()
35 {
37 }
38 
40 {
41 
42  //Temporary list of virtual slots
43  std::vector<VirtualOutputSlot*> tempOutputSlots;
44  std::vector<VirtualInputSlot*> tempInputSlots;
45 
46  //Keep smallest common number of slots
47  int nslots=std::min(num,(int)_virtualOutputSlots.size());
48  for(int i=0;i<nslots;i++)
49  {
50  tempInputSlots.push_back(_virtualInputSlots[i]);
51  tempOutputSlots.push_back(_virtualOutputSlots[i]);
52  }
53 
54  //Add more slots if needed
55  for(int i=nslots;i<num;i++)
56  {
59  out->setVirtualPartnerSlot(in);
60  tempInputSlots.push_back(in);
61  tempOutputSlots.push_back(out);
62  }
63 
64  //Remove slots if _virtualOutputSlots.size()> num
65  for(size_t i=num;i<_virtualOutputSlots.size();i++) {
66  _removeSlot(i);
67  ((VirtualOutputSlot*)_virtualOutputSlots[i])->disconnect();
68  ((VirtualInputSlot*)_virtualInputSlots[i])->disconnect();
69  delete _virtualOutputSlots[i];
70  delete _virtualInputSlots[i];
71  }
72 
73  //Remember new slotlist
74  _virtualInputSlots=tempInputSlots;
75  _virtualOutputSlots=tempOutputSlots;
76 
77  //Eventually add new slots to internal interface
78  for(int i=nslots;i<num;i++)
79  _addSlot(i);
80 
81 
82 
83 
84 }
85 
87 {
88 // _load(pf,man);
91 }
92 
94 {
95  num_slots.load(file);
96 
97  std::cout<<"num slots "<<num_slots()<<std::endl;
99 }
Parameter< int > num_slots
The number of virtual slots.
Definition: SlotBundle.h:26
void execute()
Execute.
Definition: SlotBundle.cpp:20
Interface for a plugin manager.
This class serves to store parameters used within the Charon Project.
Definition: ParameterFile.h:68
void setVirtualPartnerSlot(VirtualSlot *insl)
Set corresponding partner VirtualSlot.
Definition: Slots.cpp:277
void loadConnection(ParameterFile pf, PluginManagerInterface *man)
Load connections.
Definition: SlotBundle.cpp:86
Base class for serializable objects.
void _setDynamic(bool v)
Specifies if the ParameteredObject is dynamic.
void setNumberOfVirtualSlots(int num)
Set the number of slots.
Definition: SlotBundle.cpp:39
Declaration of the abstract class Slot and template classes InputSlot and OutputSlot.
void initialize()
Initialize.
Definition: SlotBundle.cpp:24
virtual void loadParameters(const ParameterFile &pf)
Load parameter from parameter file.
void finalize()
Finalize.
Definition: SlotBundle.cpp:27
SlotBundle(const std::string &className, const std::string &name="", const std::string &doc="")
Default constructor.
Definition: SlotBundle.cpp:4
virtual int size()
Size of bundle.
Definition: SlotBundle.cpp:30
virtual void load(const ParameterFile &pf)
Load from ParameterFile.
Definition: Parameter.hxx:109
void loadSlots(const ParameterFile &pf, const PluginManagerInterface *man)
Load slot connection from parameter file.
void prepareDynamicInterface(const ParameterFile &file)
prepare the interface of the bundle
Definition: SlotBundle.cpp:93