GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Key.cpp
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 #include "Key.h"
25 #endif
26 
27 using namespace ADF;
28 
29 /*
30 Key::KeySignature::KeySignature(std::string keytype):
31  FactoryItem("Default","",Version(0,0)),
32  fType(keytype),
33  fUniqueID(0)
34 {
35  ;
36 }
37  */
38 //Key::Key(): fSignature("Key"), fBuffer(0)
39 Key::Key(): fSignature("Default","",Version(0,0)), fBuffer(0)
40 {
41  fBuffer = new BufferIO(); // default is length 1 byte, endian type of the system
42 }
43 
44 Key::Key(BaseBuffer::EEndian e, UInt_t s): fSignature("Default","",Version(0,0)), fBuffer(0)
45 {
46  fBuffer = BufferIO::New(e,s); // return a buffer adapted for the endian of the system.
47 }
48 
49 void Key::Print(std::ostream &out) const
50 {
51  out << "[" << typeid((*this)).name()
52  << " (" << GetVersion().GetMajor() << "," << GetVersion().GetMinor() << ") ";
53 }
54 
55 /*
56 void Key::ls()
57 {
58  fBuffer->SetOffset();
59  for( UInt_t i = 0; i < fBuffer->Size() ; i++ ) {
60  Char_t c;
61  (*fBuffer) >> c;
62 
63  std::cout << c << std::endl;;
64  // printf("%s \n",c);
65  }
66 } */
67 
69 {
70 // destructor
71  delete fBuffer;
72 }
73 
74 Bool_t Key::Link(const Char_t *buf, UInt_t size)
75 {
76  if ( size >= GetKeyLength() )
77  return fBuffer->Link(buf,GetKeyLength());
78  else
79  return false;
80 }
81 
82 Bool_t Key::Link(const BufferIO &buf, UInt_t pos, UInt_t size)
83 {
84  if ( size >= GetKeyLength() )
85  return fBuffer->Link(buf,pos,GetKeyLength());
86  else
87  return false;
88 }
89 
90 Bool_t Key::Copy(const Char_t *buf, UInt_t size)
91 {
92  if ( size >= GetKeyLength() )
93  return fBuffer->Copy(buf,GetKeyLength());
94  else
95  return false;
96 }
97 
98 Bool_t Key::Copy(const Key *akey)
99 {
100 /* if ( akey == NULL || fSignature.fUniqueID != akey->GetUniqueID()
101  || akey->GetKeyLength() != GetKeyLength() ) return false;
102 
103  Move to exactly signature : see if it works
104  */
105  if ( !Key::IsAKey(akey) )
106  return false;
107 
108  return fBuffer->Copy(akey->GetRealBuffer()->GetAddress(),akey->GetKeyLength());
109 }
110 
111 
112 
virtual const BufferIO * GetRealBuffer() const
Definition: Key.h:118
Base class for a Key.
Definition: Key.h:56
virtual Bool_t Link(const Char_t *from, UInt_t from_size)
Link an external buffer to this class.
Definition: BufferIO.cpp:214
BufferIO * fBuffer
the buffer that fills in/out the Key
Definition: Key.h:99
virtual Bool_t Copy(const Char_t *, UInt_t)
Copy an external buffer to this key.
Definition: Key.cpp:90
header file for Key.cpp
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
const Char_t * GetAddress() const
Pointer to the current underlying array of bytes.
Definition: BufferIO.h:216
virtual Bool_t Copy(const Char_t *from, UInt_t from_size)
copy an external buffer to this.
Definition: BufferIO.cpp:248
static BufferIO * New(BaseBuffer::EEndian e, UInt_t s=aByte)
return the right buffer taking Into account the endian argument compared to the underlying endian sys...
Definition: BufferIO.cpp:94
UShort_t GetMinor() const
Definition: Version.h:61
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
virtual void Print(std::ostream &out=std::cout) const
Print the content of the key.
Definition: Key.cpp:49
const Int_t size
Definition: BenchIO.C:24
virtual ~Key()
Definition: Key.cpp:68
virtual Bool_t IsAKey(const Key *akey) const
Compares two keys.
Definition: Key.h:217
UShort_t GetMajor() const
Definition: Version.h:60