Logo ROOT   6.16/01
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
19TLDAPAttribute::TLDAPAttribute(const char *name) : fNCount(0)
20{
22 fValues = new TList;
24}
25
26////////////////////////////////////////////////////////////////////////////////
27/// Creates an Attribute with name and value.
28
29TLDAPAttribute::TLDAPAttribute(const char *name, const char *value)
30 : fNCount(0)
31{
33 fValues = new TList;
35 AddValue(value);
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// LDAP attribute copy ctor.
40
42 : TNamed(attr), fNCount(attr.fNCount)
43{
44 fValues = new TList;
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) {
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
76void TLDAPAttribute::AddValue(const char *value)
77{
78 fValues->AddLast(new TObjString(value));
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Delete value by name.
83
84void TLDAPAttribute::DeleteValue(const char *value)
85{
86 Int_t n = GetCount();
87 for (Int_t i = 0; i < n; 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
101const 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}
SVector< double, 2 > v
Definition: Dict.h:5
int Int_t
Definition: RtypesCore.h:41
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:363
int type
Definition: TGX11.cxx:120
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Int_t GetCount() const
void Print(Option_t *="") const
Print an attribute.
TLDAPAttribute(const char *name)
constructor
void AddValue(const char *value)
Add a value to the attribute.
LDAPMod * GetMod(Int_t op)
Get "LDAPMod" structure for attribute.
void DeleteValue(const char *value)
Delete value by name.
const char * GetValue() const
Get next value of the attribute.
TLDAPAttribute & operator=(const TLDAPAttribute &)
Equal operator.
virtual ~TLDAPAttribute()
destructor
A doubly linked list.
Definition: TList.h:44
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
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
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:51
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Collectable string class.
Definition: TObjString.h:28
const Int_t n
Definition: legend1.C:16