GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GObject.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef ADF_GObject
24 #define ADF_GObject
25 
26 #include "DataHandling.h"
27 #include "BaseBuffer.h"
28 
29 #include <vector>
30 
31 namespace ADF
32 {
33 
35 
115 class GObject
116 {
117 public:
119  typedef std::pair<ANamedItem *, std::pair<ANamedItem *,DataLink *> > FullItem;
120 
121 private:
123  std::vector <ANamedItem *> fDataItems;
125  std::vector <DataLink *> fDataLinks;
126 private:
128  void UnLink(DataLink *);
129 private:
131  std::vector< FullItem > fArrayOfItems;
132  std::vector< FullItem > fArrayOfIdleItems;
133 
134 private:
136  FullItem *IsAnItem(const Char_t *, const Char_t *);
137  FullItem *IsAnItem(const ANamedItem *);
138 
140  FullItem *IsAIdleItem(const Char_t *, const Char_t *);
141 
142 public:
144  GObject();
145 
147 
151  virtual ~GObject();
152 
154 
171  virtual Bool_t AddItem(ANamedItem *item);
172 
174  template <typename Data_t> const NamedItem<Data_t> *Get(const char *name)
175  {
176  static Data_t t; ANamedItem *proxy = 0x0; FullItem *fitem = 0x0;
177 
178  // ckeck if the asked item is an item for that object or not
179  fitem = IsAnItem(name,NamedItemTypeOf(t));
180  if ( fitem ) {
181  if ( fitem->second.first == 0x0 ) // not yet created
182  proxy = fitem->second.first = fitem->first->MakeAProxy();
183  else
184  proxy = fitem->second.first; // already there
185  }
186  else { // add it on the list of passed items
187  // check is already in the proxy list
188  fitem = IsAIdleItem(name,NamedItemTypeOf(t));
189  if ( fitem ) // item in the passed item collection
190  if ( fitem->second.first )
191  proxy = fitem->second.first;
192  else
193  proxy = fitem->second.first = fitem->first->MakeAProxy();
194  else { // create an item, its proxy and add it to the list of IdleItems
195 
196  FullItem p;
197  p.first = new NamedItem<Data_t>(name);
198  p.second.first = p.first->MakeAProxy();
199  p.second.second = 0x0;
200 
201  fArrayOfIdleItems.push_back( p );
202 
203  proxy = p.second.first;
204  }
205  }
206  if ( proxy )
207  return dynamic_cast< const NamedItem<Data_t> * >(proxy);
208  else
209  return 0x0;
210  }
212  template <typename Data_t> Bool_t Link(const char *name, Data_t *external_address)
213  {
214  Bool_t ok = false; FullItem *fitem = 0x0;
215 
216  // ckeck if the asked item is an item for that object or not
217  fitem = IsAnItem(name,NamedItemTypeOf(*external_address));
218  if ( fitem ) {
219  if ( fitem->second.second == 0x0 ) { // not yet linked so can do it
220 
221  fitem->second.second = fitem->first->MakeADataLink(external_address);
222  fDataLinks.push_back(fitem->second.second);
223 
224  ok = true;
225  } /* else {;} NO, BECAUSE ONLY ONE LINK POSSIBLE ! */
226  }
227  else { // add it on the list of passed items
228  // check is already in the passed list
229  fitem = IsAIdleItem(name,NamedItemTypeOf(*external_address));
230  if ( fitem ) { // already there
231  if ( fitem->second.second == 0x0 ) { // not yet linked so can do it
232 
233  fitem->second.second = fitem->first->MakeADataLink(external_address);
234  fDataLinks.push_back(fitem->second.second);
235 
236  } /* else {;} NO, BECAUSE ONLY ONE LINK POSSIBLE ! */
237  }
238  else { // create an item, its proxy and link add it to the list of IdleItems
239 
240  FullItem p;
241  p.first = new NamedItem<Data_t>(name);
242  p.second.first = 0x0;
243  p.second.second = p.first->MakeADataLink(external_address);
244 
245  fArrayOfIdleItems.push_back( p );
246  }
247  }
248  return ok;
249  }
250 
252  Bool_t LinkItem(const Char_t *, const Char_t *, void *);
253 // Bool_t LinkItem(const Char_t *name, Bool_t *address);
254  Bool_t LinkItem(const Char_t *name, Short_t *address);
255  Bool_t LinkItem(const Char_t *name, UShort_t *address);
256  Bool_t LinkItem(const Char_t *name, Int_t *address);
257  Bool_t LinkItem(const Char_t *name, UInt_t *address);
258  Bool_t LinkItem(const Char_t *name, Float_t *address);
259  Bool_t LinkItem(const Char_t *name, Double_t *address);
260  Bool_t LinkItem(const Char_t *name, Long64_t *address);
261  Bool_t LinkItem(const Char_t *name, ULong64_t *address);
262 
264  virtual Bool_t IsFullyLinked() const
265  { return fDataLinks.size() == fDataItems.size(); }
266 
268  virtual void SetItems(BufferIO &) const;
270  virtual void GetItems(const BufferIO &);
271 
273  virtual void SetItems();
275  virtual void GetItems() const ;
276 
278  virtual void Reset();
279 
281 
285  void TransferLinkAndProxy(GObject &to);
286 
288  virtual void Print(std::ostream &out = std::cout) const ;
289 };
290 
292 
295 {
296  static const UShort_t kMaxSize = 256u;
297 public:
298  UShort_t fRealSize;
299  Char_t fData[kMaxSize];
300 public:
301  Anonymous(Char_t c = 0) { fRealSize = 0u; ::memset(fData,c,kMaxSize); }
302  virtual ~Anonymous()
303  {;}
304 
305  template<typename Data_T> Data_T Get(UShort_t offset = 0u) const
306  {
307  if ( (offset+sizeof(Data_T)) < kMaxSize )
308  return (*(Data_T*)(fData+offset));
309  else
310  return 0;
311  }
312  template<typename Data_T> void Set(const Data_T data, UShort_t offset = 0u)
313  {
314  if ( (offset+sizeof(Data_T)) < kMaxSize )
315  *((Data_T*)(fData+offset)) = data;
316  }
317 
318  friend std::ostream & operator << (std::ostream &, const Anonymous & );
319  friend BufferIO & operator << (BufferIO &, const Anonymous & );
320  friend const BufferIO & operator >> (const BufferIO &, Anonymous &);
321 
322  Anonymous operator = (const Anonymous & a);
323 
324 // virtual void Print(std::ostream &out = std::cout) const {;}
325 
326 };
327 
328 std::ostream & operator << (std::ostream &, const Anonymous & );
329 BufferIO & operator << (BufferIO &, const Anonymous & );
330 const BufferIO & operator >> (const BufferIO &, Anonymous &);
331 
332 const char *NamedItemTypeOf(Anonymous/*s*/);
333 
335 
341 {
342 private:
343  GObject fGObject;
344 protected:
345  void ResetGlobal()
346  { fGObject.Reset(); }
347 public:
349  fGObject() {;}
350  virtual ~DataInterface()
351  {;}
352 
353  virtual GObject *Global()
354  { return &fGObject; }
355 };
356 
357 } // namespace ADF
358 #endif
359 
360 
361 
362 
363 
Data_T Get(UShort_t offset=0u) const
Definition: GObject.h:305
virtual ANamedItem * MakeAProxy()
ask this to create a proxy for it
Definition: DataHandling.h:393
std::ostream & operator<<(std::ostream &, const Anonymous &)
Definition: GObject.cpp:385
Anonymous(Char_t c=0)
Definition: GObject.h:301
virtual Bool_t AddItem(ANamedItem *item)
Add a named item to this. The item belongs to GObject and will be thus deleted.
Definition: GObject.cpp:69
void ResetGlobal()
Definition: GObject.h:345
GObject()
Constructor.
Definition: GObject.cpp:27
Base class for a Global Object.
Definition: GObject.h:115
Char_t fData[kMaxSize]
Definition: GObject.h:299
Bool_t Link(const char *name, Data_t *external_address)
General method to Link one item with an external address.
Definition: GObject.h:212
virtual void Reset()
Set local to default.
Definition: GObject.cpp:361
void TransferLinkAndProxy(GObject &to)
transfert proxy and link for one GObject to another one
Definition: GObject.cpp:193
Bool_t LinkItem(const Char_t *, const Char_t *, void *)
Only for basic type ... otherwise better to use the most general Link method.
Definition: GObject.cpp:120
std::pair< ANamedItem *, std::pair< ANamedItem *, DataLink * > > FullItem
a full item is composed of a pointer to an item, an pointer to a proxy and a pointer to a datalink ...
Definition: GObject.h:119
ANamedItem.
Definition: DataHandling.h:188
virtual DataLink * MakeADataLink(void *extern_add)
ask this to create a suitable DataLink
Definition: DataHandling.h:285
friend const BufferIO & operator>>(const BufferIO &, Anonymous &)
void Set(const Data_T data, UShort_t offset=0u)
Definition: GObject.h:312
header file for DataHandling.cpp
const BufferIO & operator>>(const BufferIO &, Anonymous &)
Definition: GObject.cpp:399
virtual Bool_t IsFullyLinked() const
to check if all the items are linked with external variables
Definition: GObject.h:264
virtual ANamedItem * MakeAProxy()=0
ask this to create a proxy for that item
virtual ~GObject()
Destructor.
Definition: GObject.cpp:34
const NamedItem< Data_t > * Get(const char *name)
to get a given item (reading mode only !!)
Definition: GObject.h:174
const char * NamedItemTypeOf(Bool_t)
UShort_t fRealSize
Definition: GObject.h:298
Anonymous operator=(const Anonymous &a)
Definition: GObject.cpp:408
virtual void Print(std::ostream &out=std::cout) const
print some informations about this object
Definition: GObject.cpp:318
Base class for a DataInterface.
Definition: GObject.h:340
friend std::ostream & operator<<(std::ostream &, const Anonymous &)
virtual ~DataInterface()
Definition: GObject.h:350
virtual void SetItems()
Copy external variables into locals.
Definition: GObject.cpp:349
virtual ~Anonymous()
Definition: GObject.h:302
virtual void GetItems() const
Copy local variables into externals.
Definition: GObject.cpp:355
virtual GObject * Global()
Definition: GObject.h:353