GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Frame.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_Frame
24 #define ADF_Frame
25 #define ADF_FRAME_H ADF_Frame
26 
27 #ifndef ADF_Key
28 #include "Key.h"
29 #endif
30 
31 #ifndef ADF_FrameFactory
32 #include "FrameFactory.h"
33 #endif
34 
35 #ifndef ADF_PtrStack
36 #include "PtrStack.h"
37 #endif
38 
39 #include <string>
40 #include <cstdio>
41 
42 namespace ADF
43 {
44 
45 class ConfigurationFrame;
46 
48 
73 class Frame
74 {
75 public:
76  friend class FrameFactory;
77 private:
79  FactoryItem fSignature;
81  Bool_t fZombie;
83 // Migration SharedFP PF_FactoryItemChange fKeyChange;
85 // Migration SharedFP PF_FactoryItemChange fFrameChange;
86 
87 private:
88  Short_t fCheckLevel;
89 
90 protected:
92  Frame();
93  Frame(Key *);
94 
97  { fSignature = item ; }
98 
99 protected:
101  virtual Bool_t DoConfigure(std::istream &)
102  { return false ; }
104  virtual Bool_t DoConfigure(std::ostream &)
105  { return false ; }
106 
107 public:
108  virtual ~Frame();
109 
111 
120  virtual void SetCheckLevel(Short_t checklevel)
121  { fCheckLevel = checklevel; }
122 
123  virtual Short_t GetCheckLevel() const
124  { return fCheckLevel; }
125 
127  const FactoryItem &GetSignature() const
128  { return fSignature; }
129 
131  virtual const BufferIO *GetRealBuffer() const = 0;
132 
134  virtual Key *GetKey() = 0;
135 
137  virtual const Key *GetKey() const = 0;
138 
140  virtual BaseBuffer::EStatus GetFrameStatus() const = 0;
141 
143  virtual void ClearFrameStatus() = 0;
144 
146  virtual UInt_t GetLength() const = 0;
147 
149 
155  virtual Bool_t Link(const Char_t *, UInt_t, const char = 'b') = 0;
156 
158 
160  virtual Bool_t Copy(const Char_t *, UInt_t, const char = 'b') = 0;
161 
163 
168  virtual Bool_t Link(const BufferIO &/*buf*/, UInt_t /*pos*/, const char /*opt*/ = 'b') = 0;
169 
171  virtual void Unlink() = 0;
172 
174  virtual Bool_t IsLinked() const = 0;
175 
177 
181  virtual Bool_t Export(BufferIO &buf) const = 0;
182 
184 
188  virtual Bool_t ExportData(BufferIO &buf) const = 0;
189 
191  virtual Bool_t Copy(const Frame *) = 0;
193  virtual Bool_t Link(const Frame *) = 0;
194 
196 
199  virtual UInt_t Read()
200  { return 0u;}
201 
203 
206  virtual UInt_t Write()
207  { return 0u;}
208 
210 
212  virtual Bool_t IsComposite() const
213  { return false; }
214 
216 
219  virtual UInt_t Scan()
220  { return 0u; }
221 
223  virtual const Key *GetSubKey(UInt_t) const = 0;
224 
226 
228  virtual UInt_t GetNbSubFrame() const
229  { return 0u; }
230 
232 
235  virtual Bool_t IsASubFrame(const Frame &)
236  { return false; }
237 
239 
242  virtual Bool_t AddSubFrame(const Frame &)
243  { return false; }
244 
246 
251  virtual Bool_t LinkSubFrame(UInt_t , Frame *)
252  { return false; }
253 
255 
257  //virtual Bool_t CopySubFrame(Int_t, Frame *) { return false; }
258 
260 
268  virtual Bool_t TransfertSubFrame(const Frame & /*from_frame*/, UInt_t /*whichsub*/)
269  { return false; }
270 
272 
279  virtual void Reset() = 0;
280 
282  virtual void FastReset() = 0;
283 
285 
288  virtual void Dump(const Char_t *filename, Bool_t anew = false) const = 0;
289  virtual Bool_t Dump(FILE *) const = 0;
290 
292  virtual Bool_t Load(FILE *) = 0;
293 
295 
299  virtual void Stallion(UInt_t repetition = 4u) = 0;
300 
302  virtual Bool_t Configure(const char *name, const char *option);
304  virtual Bool_t Configure(ConfigurationFrame *, const char *option);
305 };
306 
307 class ConcreteFrame : public Frame
308 {
309 protected:
310  BufferIO *fBuffer; // the buffer that streams in/out the content of the Frame
311  Key *fKey; // the key to map the frame
312 
313 protected:
314  virtual BufferIO *RealBuffer()
315  { return fBuffer; }
316 
317 private:
319  // ConcreteFrame();
320 
321 protected:
323  ConcreteFrame(Key *);
324 
325  virtual Bool_t LinkKey(const Char_t *buf, UInt_t size)
326  { return fKey->Link(buf,size) ; }
327 
328  virtual Bool_t CopyKey(const Char_t *buf, UInt_t size)
329  { return fKey->Copy(buf,size) ; }
330 
331  virtual Bool_t LinkFrame(const Char_t *buf, UInt_t size)
332  { return fBuffer->Link(buf,size); }
333 
334  virtual Bool_t CopyFrame(const Char_t *buf, UInt_t size)
335  { return fBuffer->Copy(buf,size); }
336 
337 public:
338  virtual ~ConcreteFrame();
339 
340  virtual const BufferIO *GetRealBuffer() const
341  { return fBuffer; }
342 
344  virtual Key *GetKey()
345  { return fKey; }
346 
348  virtual const Key *GetKey() const
349  { return fKey; }
350 
353  { return fBuffer->GetStatus(); }
354 
356  virtual void ClearFrameStatus()
358 
360  virtual UInt_t GetLength() const
361  { return fKey->GetFrameLength(); }
362 
364 
370 // virtual Bool_t Link(Char_t *buf, UInt_t size)
371 // {
372 // return LinkKey(buf,size) && LinkFrame(buf+fKey->GetKeyLength(),size-fKey->GetKeyLength());
373 // }
374  virtual Bool_t Link(const Char_t *buf, UInt_t size, const char opt = 'b')
375  {
376  if ( opt == 'k' )
377  return LinkKey(buf,size);
378  if ( opt == 'f' )
379  return LinkFrame(buf,size);
380 
381  return (LinkKey(buf,size) && LinkFrame(buf+fKey->GetKeyLength(),size-fKey->GetKeyLength()));
382  }
383 // virtual Bool_t Copy(Char_t *buf, UInt_t size)
384 // {
385 // return false;
386 // }
387  virtual Bool_t Copy(const Char_t *buf, UInt_t size, const char opt = 'b')
388  {
389  if ( opt == 'k' )
390  return CopyKey(buf,size);
391  if ( opt == 'f' )
392  return CopyFrame(buf,size);
393 
394  return (CopyKey(buf,size) && CopyFrame(buf+fKey->GetKeyLength(),size-fKey->GetKeyLength()));
395  }
396 
398 
400 // virtual Bool_t Copy(const Char_t *buf, UInt_t size)
401 // {
402 // return CopyKey(buf,size) && CopyFrame(buf+fKey->GetKeyLength(),size-fKey->GetKeyLength());
403 // }
404 
406 
411  virtual Bool_t Link(const BufferIO &buf, UInt_t pos, const Char_t opt = 'b')
412  {
413  if ( opt == 'k' )
414  return fKey->Link(buf,pos,fKey->GetKeyLength());
415  if ( opt == 'f' )
416  return fBuffer->Link(buf,pos+fKey->GetKeyLength(),fKey->GetDataLength());
417 
418  return fKey->Link(buf,pos,fKey->GetKeyLength())
419  && fBuffer->Link(buf,pos+fKey->GetKeyLength(),fKey->GetDataLength());
420  }
421 
423 
428 // virtual Bool_t Copy(BufferIO &buf, UInt_t pos)
429 // { return fKey->Copy(buf,pos,fKey->GetKeyLength())
430 // && fBuffer->Copy(buf,pos+fKey->GetKeyLength(),fKey->GetDataLength()); }
431 
433  virtual void Unlink()
434  { fKey->Unlink(); fBuffer->Unlink(); }
435 
436  virtual Bool_t IsLinked() const
437  { return fBuffer->IsLinked() && fKey->IsLinked(); }
438 
440  virtual Bool_t Copy(const Frame *);
442  virtual Bool_t Link(const Frame *);
443 
445 
449  virtual Bool_t Export(BufferIO &buf) const
450  {
451  Bool_t ok = fKey->Export(buf);
452  UInt_t length = fKey->GetDataLength();
453 
454 // ok = ok && buf.Import((*fBuffer),fKey->GetDataLength()) == fKey->GetDataLength();
455  ok = ok && (buf.Import((*fBuffer),length) == length);
456  return ok;
457  }
458 
460 
464  virtual Bool_t ExportData(BufferIO &buf) const
465  { return BufferIO::Copy((*fBuffer),buf,fKey->GetDataLength()); }
466 
467 
469 
471  virtual Bool_t IsComposite() const
472  { return false; }
473 
475 
478  virtual UInt_t Scan()
479  { return 0u; }
480 
482  virtual const Key *GetSubKey(UInt_t) const
483  { return fKey; }
484 
486 
488  virtual UInt_t GetNbSubFrame() const
489  { return 0u; }
490 
492 
495  virtual Bool_t AddSubFrame(const Frame &)
496  { return false; }
497 
499 
505  virtual Bool_t LinkSubFrame(UInt_t , Frame *)
506  { return false; }
507 
509 
511  //virtual Bool_t CopySubFrame(Int_t, Frame *) { return false; }
512 
514 
522  virtual void Reset()
523  { fBuffer->Reset(); fBuffer->SetOffset(); fKey->SetDataLength(0u); }
524 
526  virtual void FastReset()
527  { fBuffer->SetOffset(); fKey->SetDataLength(0u); }
528 
530 
538  virtual void Dump(const Char_t *filename, Bool_t anew = false) const ;
539  virtual Bool_t Dump(FILE *) const;
540 
542  virtual Bool_t Load(FILE *);
543 
545 
549  virtual void Stallion(UInt_t repetition = 4u);
550 };
551 // ConcreteFrame inline members //////////////////////////////////////////////////////
552 
554 
557 class RawFrame : public ConcreteFrame
558 {
559 public:
561  {;}
562  virtual ~RawFrame()
563  {;}
564 
566 
568  virtual UInt_t Read()
569  { return GetKey()->GetDataLength(); }
570 
572 
576  virtual UInt_t Write()
577  { GetKey()->SetDataLength(GetRealBuffer()->Offset()); return GetKey()->GetDataLength(); }
578 
580  virtual BufferIO &RawBuffer()
581  { return (*RealBuffer()); }
582 };
583 
585 
597 class SharedFP
598 {
599 private:
600  Frame *fFrame;
601 private:
603  Bool_t fIsValid;
604 private:
606  PF_FactoryItemChange fKeyChange;
608  PF_FactoryItemChange fFrameChange;
609 
610 public:
611  explicit SharedFP( Frame *f = 0x0 );
612  virtual ~SharedFP()
613  { if (fFrame) delete fFrame ; fFrame = 0x0; }
614 
616  virtual Bool_t IsValid() const
617  { return fIsValid; }
619  virtual void SetValid(Bool_t validity)
620  { fIsValid = validity; }
621 
623  virtual Frame *SetFrame(Frame *);
624 
625  virtual Frame * GetFrame() const
626  { return fFrame; }
627 
629 
631  Bool_t IsKeyChangeable(FactoryItem item_from, FactoryItem item_to) const
632  { return fKeyChange(item_from,item_to); }
633 
635  { fKeyChange = pf; }
636 
638  { return fKeyChange; }
639 
641 
643  Bool_t IsFrameChangeable(FactoryItem item_from, FactoryItem item_to) const
644  { return fFrameChange(item_from,item_to); }
645 
647  { fFrameChange = pf; }
648 
650  { return fFrameChange; }
651 };
652 
653 } // namespace ADF
654 #endif
655 
656 
657 
658 
virtual const Key * GetSubKey(UInt_t) const =0
Returns one of the sub-key in case this is a composite frame.
virtual UInt_t GetLength() const
total length for that frame
Definition: Frame.h:360
virtual BufferIO * RealBuffer()
Definition: Frame.h:314
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
virtual Bool_t Copy(const Char_t *buf, UInt_t size, const char opt= 'b')
copy a buffer to this Frame
Definition: Frame.h:387
virtual Key * GetKey()=0
To get the Key associated to this frame.
void SetStatus(BufferIO::EStatus s=BaseBuffer::kGood)
Definition: BufferIO.h:106
virtual Frame * GetFrame() const
Definition: Frame.h:625
virtual ~RawFrame()
Definition: Frame.h:562
Base class for a Key.
Definition: Key.h:56
BufferIO::EStatus GetStatus() const
Definition: BufferIO.h:109
virtual Bool_t TransfertSubFrame(const Frame &, UInt_t)
copy the sub-frame #i to the Frame given in the second argument
Definition: Frame.h:268
Base class for a FrameFactory.
Definition: FrameFactory.h:49
virtual Bool_t AddSubFrame(const Frame &)
Add a subframe to that frame (only if composite)
Definition: Frame.h:495
Base class for a Frame.
Definition: Frame.h:73
virtual void Unlink()
Copy a buffer to this Frame.
Definition: Frame.h:433
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
Definition: Frame.h:199
virtual Bool_t Link(const Char_t *from, UInt_t from_size)
Link an external buffer to this class.
Definition: BufferIO.cpp:214
virtual Bool_t Export(BufferIO &buf) const
Export the content of the frame in a buffer.
Definition: Frame.h:449
virtual void FastReset()=0
FastReset the current frame, means the data part keep the previous values.
virtual Bool_t CopyKey(const Char_t *buf, UInt_t size)
Definition: Frame.h:328
virtual void Reset()
Reset means set all elements to 0 and the current position is 0.
Definition: BufferIO.cpp:109
virtual Bool_t IsComposite() const
tells if this frame is a composite frame i.e. if it is composed of sub-frames
Definition: Frame.h:471
virtual Bool_t Link(const BufferIO &buf, UInt_t pos, const Char_t opt= 'b')
copy a buffer to this Frame
Definition: Frame.h:411
virtual Bool_t IsLinked() const
Definition: Key.h:170
virtual Bool_t ExportData(BufferIO &buf) const
Export the content of the frame (data part only) in a buffer.
Definition: Frame.h:464
A configuration frame is just an encapsulation of a string.
virtual Bool_t Copy(const Char_t *, UInt_t)
Copy an external buffer to this key.
Definition: Key.cpp:90
virtual Bool_t Load(FILE *)
load a Frame from a C file (for debugging) - return the number of bytes read
Definition: Frame.cpp:209
Bool_t IsKeyChangeable(FactoryItem item_from, FactoryItem item_to) const
true if for that Frame the key modification proposed is acceptable
Definition: Frame.h:631
virtual const BufferIO * GetRealBuffer() const =0
give access to the underlying buffer of the data part
RawFrame(Key *key)
Definition: Frame.h:560
virtual void Dump(const Char_t *filename, Bool_t anew=false) const
Dump the content of the frame in a file (for debugging)
Definition: Frame.cpp:180
virtual Bool_t LinkFrame(const Char_t *buf, UInt_t size)
Definition: Frame.h:331
virtual Bool_t IsLinked() const
true if the underlying buffers have been linked.
Definition: Frame.h:436
virtual Key * GetKey()
To get the Key associated to this frame.
Definition: Frame.h:344
virtual ~SharedFP()
Definition: Frame.h:612
virtual const Key * GetKey() const
To get the Key associated to this frame.
Definition: Frame.h:348
virtual UInt_t GetDataLength() const
Definition: Key.h:134
virtual Bool_t Link(const Char_t *buf, UInt_t size, const char opt= 'b')
Link a buffer to this Frame.
Definition: Frame.h:374
virtual void SetFrameChangeFunction(PF_FactoryItemChange pf)
Definition: Frame.h:646
virtual Bool_t ExportData(BufferIO &buf) const =0
Export the content of the frame (data part only) in a buffer.
Bool_t(* PF_FactoryItemChange)(const FactoryItem &, const FactoryItem &)
prototype function to control the evolution of a factory item.
Definition: FactoryItem.h:127
virtual Bool_t IsLinked()
check if this is linked or not
Definition: BufferIO.h:160
virtual Char_t * Unlink()
Unlink the external buffer to this class.
Definition: BufferIO.cpp:373
header file for Key.cpp
virtual Bool_t Export(BufferIO &buf) const =0
Export the content of the frame in a buffer.
virtual void SetValid(Bool_t validity)
true if it is a valid pointer
Definition: Frame.h:619
const PF_FactoryItemChange & GetKeyChangeFunction() const
Definition: Frame.h:637
BufferIO * fBuffer
Definition: Frame.h:310
virtual UInt_t Scan()
Scan this Frame. If it is a composite frame, it looks for the keys of sub-frames. ...
Definition: Frame.h:478
virtual Bool_t IsComposite() const
tells if this frame is a composite frame i.e. if it is composed of sub-frames
Definition: Frame.h:212
virtual const Key * GetSubKey(UInt_t) const
Returns one of the sub-key in case this is a composite frame.
Definition: Frame.h:482
virtual Bool_t Configure(const char *name, const char *option)
configuration from/to a file
Definition: Frame.cpp:58
void SetSignature(FactoryItem item)
to change the signature of that frame
Definition: Frame.h:96
virtual void Stallion(UInt_t repetition=4u)
Fill the frame with a given pattern (used for debugging)
Definition: Frame.cpp:229
virtual BaseBuffer::EStatus GetFrameStatus() const
To get the current status of this frame.
Definition: Frame.h:352
virtual UInt_t GetNbSubFrame() const
Returns the number of sub-frames composing this frame. Scan have to be called first.
Definition: Frame.h:488
virtual UInt_t GetKeyLength() const
Unique number corresponding to a type of Key.
Definition: Key.h:210
virtual void ClearFrameStatus()
To clear to kGood the current status of this frame.
Definition: Frame.h:356
virtual void Reset()
copy the sub-frame #i to the Frame given in the second argument
Definition: Frame.h:522
template header file
virtual Bool_t CopyFrame(const Char_t *buf, UInt_t size)
Definition: Frame.h:334
virtual UInt_t Write()
It just set the size of the frame from the current position in the buffer.
Definition: Frame.h:576
virtual void Unlink()=0
UnLink a buffer to this Frame.
virtual BaseBuffer::EStatus GetFrameStatus() const =0
To get the current status of this frame.
A RawFrame gives direct access to the underlying buffer.
Definition: Frame.h:557
ConcreteFrame(Key *)
Definition: Frame.cpp:115
virtual UInt_t Write()
It writes to the Frame the content of the dedicated structures.
Definition: Frame.h:206
virtual Bool_t Copy(const Char_t *from, UInt_t from_size)
copy an external buffer to this.
Definition: BufferIO.cpp:248
virtual UInt_t Read()
It just returns the current size of the buffer.
Definition: Frame.h:568
virtual BufferIO & RawBuffer()
This method gives access in reading/writing mode to the underlying data buffer.
Definition: Frame.h:580
virtual ~Frame()
Definition: Frame.cpp:54
Frame()
To avoid direct creation of a Frame.
Definition: Frame.cpp:38
virtual UInt_t GetLength() const =0
total length for that frame
A Shared Frame Pointer.
Definition: Frame.h:597
virtual Bool_t DoConfigure(std::ostream &)
write the configuration in an output stream
Definition: Frame.h:104
virtual Bool_t Export(BufferIO &buf) const
to copy the content of the key to an external buffer
Definition: Key.h:185
virtual const BufferIO * GetRealBuffer() const
give access to the underlying buffer of the data part
Definition: Frame.h:340
virtual Short_t GetCheckLevel() const
Definition: Frame.h:123
virtual Bool_t Link(const Char_t *, UInt_t)
Link an external buffer to this key.
Definition: Key.cpp:74
virtual void Reset()=0
Reset the current frame.
virtual Bool_t LinkSubFrame(UInt_t, Frame *)
Attach the sub-frame corresponding to the given subkey # to the Frame given in the second argument...
Definition: Frame.h:251
virtual Frame * SetFrame(Frame *)
change the frame, returns the current one
Definition: Frame.cpp:275
virtual void Stallion(UInt_t repetition=4u)=0
Fill the frame with a given pattern (used for ADF test)
virtual void Unlink()
Unlink the buffer attached to this key.
Definition: Key.h:167
virtual Bool_t Copy(const Char_t *, UInt_t, const char= 'b')=0
copy a buffer to this Frame
virtual void SetCheckLevel(Short_t checklevel)
The number of tests (and the speed !) once writing/reading in Frame increase with this level...
Definition: Frame.h:120
virtual void SetKeyChangeFunction(PF_FactoryItemChange pf)
Definition: Frame.h:634
Bool_t IsFrameChangeable(FactoryItem item_from, FactoryItem item_to) const
true if for that Frame the frame modification proposed is acceptable
Definition: Frame.h:643
virtual Bool_t Link(const Char_t *, UInt_t, const char= 'b')=0
Link a buffer to this Frame.
UInt_t Import(const Char_t *from, UInt_t size_ext_buf)
Import the given array in this buffer.
Definition: BufferIO.cpp:298
SharedFP(Frame *f=0x0)
Definition: Frame.cpp:266
virtual void ClearFrameStatus()=0
To clear to kGood the current status of this frame.
virtual void Dump(const Char_t *filename, Bool_t anew=false) const =0
Dump the content of the frame in a file (for debugging)
EStatus
Status for this buffer.
Definition: BaseBuffer.h:57
virtual Bool_t IsASubFrame(const Frame &)
to check if a subframe could be added to the composite frame
Definition: Frame.h:235
virtual Bool_t Load(FILE *)=0
load a Frame from a C file (for debugging)
virtual UInt_t Scan()
Scan this Frame. If it is a composite frame, it looks for the keys of sub-frames. ...
Definition: Frame.h:219
virtual Bool_t AddSubFrame(const Frame &)
Add a subframe to that frame (only if composite)
Definition: Frame.h:242
virtual Bool_t LinkKey(const Char_t *buf, UInt_t size)
Definition: Frame.h:325
header file for FrameFactory.cpp
virtual UInt_t GetNbSubFrame() const
Returns the number of sub-frames composing this frame. Scan have to be called first.
Definition: Frame.h:228
virtual Bool_t DoConfigure(std::istream &)
configure this from an input stream
Definition: Frame.h:101
const Int_t size
Definition: BenchIO.C:24
virtual Bool_t IsLinked() const =0
true if the underlying buffers have been linked.
virtual void FastReset()
FastReset the current frame, means the data part keep the previous values.
Definition: Frame.h:526
virtual ~ConcreteFrame()
Definition: Frame.cpp:130
virtual Bool_t LinkSubFrame(UInt_t, Frame *)
Attach the sub-frame corresponding to the given subkey to the Frame given in the second argument...
Definition: Frame.h:505
virtual UInt_t GetFrameLength() const
Definition: Key.h:136
const PF_FactoryItemChange & GetFrameChangeFunction() const
Definition: Frame.h:649
Base class that described an item in a Factory.
Definition: FactoryItem.h:52
const FactoryItem & GetSignature() const
Signature of that frame.
Definition: Frame.h:127
UInt_t SetOffset(UInt_t off=0u) const
change the current position.
Definition: BufferIO.cpp:122