Logo ROOT   6.12/07
Reference Guide
TLDAPAttribute.cxx
Go to the documentation of this file.
1 // @(#)root/ldap:$Id$
2 // Author: Evgenia Smirnova 21/09/2001
3 
4 /*************************************************************************
5  * For the licensing terms see $ROOTSYS/LICENSE. *
6  * For the list of contributors see $ROOTSYS/README/CREDITS. *
7  *************************************************************************/
8 
9 #include "TLDAPAttribute.h"
10 #include "TObjString.h"
11 #include "Riostream.h"
12 
13 
15 
16 ////////////////////////////////////////////////////////////////////////////////
17 ///constructor
18 
19 TLDAPAttribute::TLDAPAttribute(const char *name) : fNCount(0)
20 {
21  SetName(name);
22  fValues = new TList;
23  fValues->SetOwner();
24 }
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Creates an Attribute with name and value.
28 
29 TLDAPAttribute::TLDAPAttribute(const char *name, const char *value)
30  : fNCount(0)
31 {
32  SetName(name);
33  fValues = new TList;
34  fValues->SetOwner();
35  AddValue(value);
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// LDAP attribute copy ctor.
40 
42  : TNamed(attr), fNCount(attr.fNCount)
43 {
44  fValues = new TList;
45  fValues->SetOwner();
46 
47  TIter next(attr.fValues);
48  while (TObjString *str = (TObjString*) next()) {
49  fValues->AddLast(new TObjString(str->GetName()));
50  }
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Equal operator
55 
57 {
58  if(this!=&attr) {
59  TNamed::operator=(attr);
60  fValues=attr.fValues;
61  fNCount=attr.fNCount;
62  } return *this;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 ///destructor
67 
69 {
70  delete fValues;
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Add a value to the attribute.
75 
76 void TLDAPAttribute::AddValue(const char *value)
77 {
78  fValues->AddLast(new TObjString(value));
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Delete value by name.
83 
84 void TLDAPAttribute::DeleteValue(const char *value)
85 {
86  Int_t n = GetCount();
87  for (Int_t i = 0; i < n; i++) {
88  TObjString *v = (TObjString*) fValues->At(i);
89  if (v->String().CompareTo(value) == 0) {
90  delete fValues->Remove(v);
91  if (fNCount > i) fNCount--;
92  return;
93  }
94  }
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Get next value of the attribute. Returns zero after the last value,
99 /// then returns the first value again.
100 
101 const char *TLDAPAttribute::GetValue() const
102 {
103  Int_t n = GetCount();
104  if (n > fNCount) {
105  return ((TObjString*)fValues->At(fNCount++))->GetName();
106  } else {
107  fNCount = 0;
108  return 0;
109  }
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Print an attribute.
114 
116 {
117  Int_t counter = GetCount();
118  if (counter == 0) {
119  std::cout << GetName() << ": " << std::endl;
120  } else if (counter != 0) {
121  for (Int_t i = 0; i < counter; i++) {
122  std::cout << GetName() << ": " << GetValue() << std::endl;
123  }
124  }
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Get "LDAPMod" structure for attribute. Returned LDAPMod must be
129 /// deleted by the user.
130 
132 {
133  LDAPMod *tmpMod = new LDAPMod;
134  Int_t iCount = GetCount();
135  char **values = new char* [iCount + 1];
136  char *type = new char [strlen(GetName())+1];
137  for (int i = 0; i < iCount; i++) {
138  int nch = strlen(((TObjString*)fValues->At(i))->GetName()) + 1;
139  values[i] = new char [nch];
140  strlcpy(values[i], ((TObjString*)fValues->At(i))->GetName(),nch);
141  }
142 
143  values[iCount] = 0;
144  strlcpy(type, GetName(),strlen(GetName())+1);
145  tmpMod->mod_values = values;
146  tmpMod->mod_type = type;
147  tmpMod->mod_op = op;
148 
149  return tmpMod;
150 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void DeleteValue(const char *value)
Delete value by name.
void AddValue(const char *value)
Add a value to the attribute.
Collectable string class.
Definition: TObjString.h:28
const char Option_t
Definition: RtypesCore.h:62
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
int Int_t
Definition: RtypesCore.h:41
TLDAPAttribute(const char *name)
constructor
virtual void AddLast(TObject *obj)
Add object at the end of the list.
Definition: TList.cxx:149
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
A doubly linked list.
Definition: TList.h:44
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:51
SVector< double, 2 > v
Definition: Dict.h:5
TLDAPAttribute & operator=(const TLDAPAttribute &)
Equal operator.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:354
TString & String()
Definition: TObjString.h:49
#define ClassImp(name)
Definition: Rtypes.h:359
int type
Definition: TGX11.cxx:120
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:396
Int_t GetCount() const
LDAPMod * GetMod(Int_t op)
Get "LDAPMod" structure for attribute.
virtual ~TLDAPAttribute()
destructor
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
const char * GetValue() const
Get next value of the attribute.
void Print(Option_t *="") const
Print an attribute.