GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Key.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_Key
24 #define ADF_Key
25 #define ADF_KEY_H ADF_Key
26 
27 #ifndef ADF_BufferIO
28 #include "BufferIO.h"
29 #endif
30 
31 #ifndef ADF_FactoryItem
32 #include "FactoryItem.h"
33 #endif
34 
35 #include <typeinfo>
36 
37 namespace ADF
38 {
39 
40 class KeyFactory;
41 class ConcreteFrame;
42 
44 
56 class Key
57 {
58 public:
59  friend class KeyFactory;
60  friend class ConcreteFrame;
61 
62 private:
64  /*
65  class KeySignature : public FactoryItem
66  {
67  public:
68  KeySignature(std::string);
69 
70  std::string fType; // type of this key ... corresponding to the interface
71  UInt_t fUniqueID; // KeyID as delivered by the KeyFactory, helps to compare Keys
72  };
73  KeySignature fSignature; */
74  FactoryItem fSignature;
75 
76 protected:
78  { return fSignature.GetVersion() ; }
79 
80 protected:
82 
87  virtual BufferIO *RealBuffer()
88  { return fBuffer; }
89 
90 private:
92  void SetDataLength(Int_t)
93  {;}
94  void SetDataLength(Short_t)
95  {;}
96 
97 protected:
100 
101 private:
103  Key();
104 
105 protected:
107 
110  Key(BaseBuffer::EEndian, UInt_t s);
111 
112 public:
113  virtual ~Key();
114 
115  const FactoryItem &GetSignature() const
116  { return fSignature; }
117 
118  virtual const BufferIO *GetRealBuffer() const
119  { return fBuffer; }
120 
122  { return fBuffer->GetStatus();}
123  virtual void ClearKeyStatus()
125 
127  { return fBuffer->GetEndian(); }
128 
129  virtual void SetDataLength(UShort_t)
131  virtual void SetDataLength(UInt_t)
133 
134  virtual UInt_t GetDataLength() const
135  { return 0u; }
136  virtual UInt_t GetFrameLength() const
137  { return GetKeyLength() + GetDataLength(); }
138 
139  virtual const Char_t *GetAddress() const
140  { return fBuffer->GetAddress(); }
141 
143 
149  virtual Bool_t Link(const Char_t *, UInt_t);
150 
152 
158  virtual Bool_t Link(const BufferIO &buf, UInt_t pos, UInt_t size);
159 
161 
164  virtual Bool_t Copy(const Char_t *, UInt_t);
165 
167  virtual void Unlink()
168  { fBuffer->Unlink(); }
169 
170  virtual Bool_t IsLinked() const
171  { return fBuffer->IsLinked(); }
172 
174 
179  virtual Bool_t Copy(const Key *);
180 
182 
185  virtual Bool_t Export(BufferIO &buf) const
186  {
187  Bool_t ok =
188  (buf.Import((*fBuffer),fBuffer->Size()) == fBuffer->Size());
189  return ok;
190  }
191 
193 
197 // UInt_t GetUniqueID() const
198 // { return fSignature.fUniqueID; }
199 
201 
204 // virtual const std::string &GetKeyType() const
205 // { return fSignature.fType ; }
206 
208 
210  virtual UInt_t GetKeyLength() const
211  { return fBuffer->Size(); }
212 
214 
217  virtual Bool_t IsAKey(const Key *akey) const
218  {
219  return fSignature == akey->GetSignature();
220  }
221 
223 
226  virtual Bool_t Convert(const Key *akey)
227  {
228  // to test if the length could be stream from one key to another one (ex : length could be too high converting int to short)
229  fBuffer->SetStatus();
230  // copy data /frame length
231  SetDataLength(akey->GetDataLength());
232 
233  return fBuffer->GetStatus() == BaseBuffer::kGood;
234  }
235 
237  virtual void Print(std::ostream &out = std::cout) const;
238 };
239 // Key inline members //////////////////////////////////////////////////////
240 
241 } // namespace ADF
242 #endif
243 
244 
245 
246 
247 
virtual const BufferIO * GetRealBuffer() const
Definition: Key.h:118
void SetStatus(BufferIO::EStatus s=BaseBuffer::kGood)
Definition: BufferIO.h:106
Base class for a Key.
Definition: Key.h:56
BufferIO::EStatus GetStatus() const
Definition: BufferIO.h:109
header file for FactoryItem.cpp
BufferIO * fBuffer
the buffer that fills in/out the Key
Definition: Key.h:99
const FactoryItem & GetSignature() const
Definition: Key.h:115
virtual Bool_t IsLinked() const
Definition: Key.h:170
virtual BufferIO * RealBuffer()
Used by specific methods.
Definition: Key.h:87
virtual Bool_t Copy(const Char_t *, UInt_t)
Copy an external buffer to this key.
Definition: Key.cpp:90
virtual UInt_t GetDataLength() const
Definition: Key.h:134
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
virtual BaseBuffer::EStatus GetKeyStatus() const
Definition: Key.h:121
virtual BaseBuffer::EEndian GetEndian() const
Definition: Key.h:126
UInt_t Size() const
it returns the maximum number of bytes in this buffer
Definition: BufferIO.h:220
virtual UInt_t GetKeyLength() const
Unique number corresponding to a type of Key.
Definition: Key.h:210
Base class for version numbers.
Definition: Version.h:38
header file for BufferIO.cpp
const Char_t * GetAddress() const
Pointer to the current underlying array of bytes.
Definition: BufferIO.h:216
virtual const Char_t * GetAddress() const
Definition: Key.h:139
virtual void ClearKeyStatus()
Definition: Key.h:123
virtual Bool_t Export(BufferIO &buf) const
to copy the content of the key to an external buffer
Definition: Key.h:185
Version GetVersion() const
Definition: Key.h:77
virtual Bool_t Link(const Char_t *, UInt_t)
Link an external buffer to this key.
Definition: Key.cpp:74
Version GetVersion() const
Definition: FactoryItem.h:88
virtual Bool_t Convert(const Key *akey)
convert a key to another key ... not an easy task ... use it carefully
Definition: Key.h:226
BaseBuffer::EEndian GetEndian() const
Definition: BufferIO.h:112
virtual void Unlink()
Unlink the buffer attached to this key.
Definition: Key.h:167
virtual void SetDataLength(UShort_t)
Definition: Key.h:129
virtual void SetDataLength(UInt_t)
Definition: Key.h:131
UInt_t Import(const Char_t *from, UInt_t size_ext_buf)
Import the given array in this buffer.
Definition: BufferIO.cpp:298
virtual void Print(std::ostream &out=std::cout) const
Print the content of the key.
Definition: Key.cpp:49
EStatus
Status for this buffer.
Definition: BaseBuffer.h:57
const Int_t size
Definition: BenchIO.C:24
virtual ~Key()
Definition: Key.cpp:68
Base Key factory.
Definition: KeyFactory.h:44
virtual Bool_t IsAKey(const Key *akey) const
Compares two keys.
Definition: Key.h:217
virtual UInt_t GetFrameLength() const
Definition: Key.h:136
Base class that described an item in a Factory.
Definition: FactoryItem.h:52