ROOT logo
// @(#)root/ldap:$Id$
// Author: Evgenia Smirnova   21/09/2001

/*************************************************************************
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TLDAPAttribute.h"
#include "TObjString.h"
#include "Riostream.h"


ClassImp(TLDAPAttribute)

//______________________________________________________________________________
TLDAPAttribute::TLDAPAttribute(const char *name) : fNCount(0)
{
   //constructor
   SetName(name);
   fValues = new TList;
   fValues->SetOwner();
}

//______________________________________________________________________________
TLDAPAttribute::TLDAPAttribute(const char *name, const char *value)
   : fNCount(0)
{
   // Creates an Attribute with name and value.

   SetName(name);
   fValues = new TList;
   fValues->SetOwner();
   AddValue(value);
}

//______________________________________________________________________________
TLDAPAttribute::TLDAPAttribute(const TLDAPAttribute &attr)
   : TNamed(attr), fNCount(attr.fNCount)
{
   // LDAP attribute copy ctor.

   fValues = new TList;
   fValues->SetOwner();

   TIter next(attr.fValues);
   while (TObjString *str = (TObjString*) next()) {
      fValues->AddLast(new TObjString(str->GetName()));
   }
}

//______________________________________________________________________________
TLDAPAttribute& TLDAPAttribute::operator=(const TLDAPAttribute &attr)
{
   // Equal operator
   if(this!=&attr) {
      TNamed::operator=(attr);
      fValues=attr.fValues;
      fNCount=attr.fNCount;
   } return *this;
}

//______________________________________________________________________________
TLDAPAttribute::~TLDAPAttribute()
{
   //destructor
   delete fValues;
}

//______________________________________________________________________________
void TLDAPAttribute::AddValue(const char *value)
{
   // Add a value to the attribute.

   fValues->AddLast(new TObjString(value));
}

//______________________________________________________________________________
void TLDAPAttribute::DeleteValue(const char *value)
{
   // Delete value by name.

   Int_t n = GetCount();
   for (Int_t i = 0; i < n; i++) {
      TObjString *v = (TObjString*) fValues->At(i);
      if (v->String().CompareTo(value) == 0) {
         delete fValues->Remove(v);
         if (fNCount > i) fNCount--;
         return;
      }
   }
}

//______________________________________________________________________________
const char *TLDAPAttribute::GetValue() const
{
   // Get next value of the attribute. Returns zero after the last value,
   // then returns the first value again.

   Int_t n = GetCount();
   if (n > fNCount) {
      return ((TObjString*)fValues->At(fNCount++))->GetName();
   } else {
      fNCount = 0;
      return 0;
   }
}

//_______________________________________________________________________________
void TLDAPAttribute::Print(Option_t *) const
{
   // Print an attribute.

   Int_t counter = GetCount();
   if (counter == 0) {
      cout << GetName() << ": " << endl;
   } else if (counter != 0) {
      for (Int_t i = 0; i < counter; i++) {
         cout << GetName() << ": " << GetValue() << endl;
      }
   }
}

//_______________________________________________________________________________
LDAPMod *TLDAPAttribute::GetMod(Int_t op)
{
   // Get "LDAPMod" structure for attribute. Returned LDAPMod must be
   // deleted by the user.

   LDAPMod *tmpMod = new LDAPMod;
   Int_t iCount = GetCount();
   char **values = new char* [iCount + 1];
   char *type = new char [strlen(GetName())+1];
   for (int i = 0; i < iCount; i++) {
      int nch = strlen(((TObjString*)fValues->At(i))->GetName()) + 1;
      values[i] = new char [nch];
      strlcpy(values[i], ((TObjString*)fValues->At(i))->GetName(),nch);
   }

   values[iCount] = 0;
   strlcpy(type, GetName(),strlen(GetName())+1);
   tmpMod->mod_values = values;
   tmpMod->mod_type = type;
   tmpMod->mod_op = op;

   return tmpMod;
}
 TLDAPAttribute.cxx:1
 TLDAPAttribute.cxx:2
 TLDAPAttribute.cxx:3
 TLDAPAttribute.cxx:4
 TLDAPAttribute.cxx:5
 TLDAPAttribute.cxx:6
 TLDAPAttribute.cxx:7
 TLDAPAttribute.cxx:8
 TLDAPAttribute.cxx:9
 TLDAPAttribute.cxx:10
 TLDAPAttribute.cxx:11
 TLDAPAttribute.cxx:12
 TLDAPAttribute.cxx:13
 TLDAPAttribute.cxx:14
 TLDAPAttribute.cxx:15
 TLDAPAttribute.cxx:16
 TLDAPAttribute.cxx:17
 TLDAPAttribute.cxx:18
 TLDAPAttribute.cxx:19
 TLDAPAttribute.cxx:20
 TLDAPAttribute.cxx:21
 TLDAPAttribute.cxx:22
 TLDAPAttribute.cxx:23
 TLDAPAttribute.cxx:24
 TLDAPAttribute.cxx:25
 TLDAPAttribute.cxx:26
 TLDAPAttribute.cxx:27
 TLDAPAttribute.cxx:28
 TLDAPAttribute.cxx:29
 TLDAPAttribute.cxx:30
 TLDAPAttribute.cxx:31
 TLDAPAttribute.cxx:32
 TLDAPAttribute.cxx:33
 TLDAPAttribute.cxx:34
 TLDAPAttribute.cxx:35
 TLDAPAttribute.cxx:36
 TLDAPAttribute.cxx:37
 TLDAPAttribute.cxx:38
 TLDAPAttribute.cxx:39
 TLDAPAttribute.cxx:40
 TLDAPAttribute.cxx:41
 TLDAPAttribute.cxx:42
 TLDAPAttribute.cxx:43
 TLDAPAttribute.cxx:44
 TLDAPAttribute.cxx:45
 TLDAPAttribute.cxx:46
 TLDAPAttribute.cxx:47
 TLDAPAttribute.cxx:48
 TLDAPAttribute.cxx:49
 TLDAPAttribute.cxx:50
 TLDAPAttribute.cxx:51
 TLDAPAttribute.cxx:52
 TLDAPAttribute.cxx:53
 TLDAPAttribute.cxx:54
 TLDAPAttribute.cxx:55
 TLDAPAttribute.cxx:56
 TLDAPAttribute.cxx:57
 TLDAPAttribute.cxx:58
 TLDAPAttribute.cxx:59
 TLDAPAttribute.cxx:60
 TLDAPAttribute.cxx:61
 TLDAPAttribute.cxx:62
 TLDAPAttribute.cxx:63
 TLDAPAttribute.cxx:64
 TLDAPAttribute.cxx:65
 TLDAPAttribute.cxx:66
 TLDAPAttribute.cxx:67
 TLDAPAttribute.cxx:68
 TLDAPAttribute.cxx:69
 TLDAPAttribute.cxx:70
 TLDAPAttribute.cxx:71
 TLDAPAttribute.cxx:72
 TLDAPAttribute.cxx:73
 TLDAPAttribute.cxx:74
 TLDAPAttribute.cxx:75
 TLDAPAttribute.cxx:76
 TLDAPAttribute.cxx:77
 TLDAPAttribute.cxx:78
 TLDAPAttribute.cxx:79
 TLDAPAttribute.cxx:80
 TLDAPAttribute.cxx:81
 TLDAPAttribute.cxx:82
 TLDAPAttribute.cxx:83
 TLDAPAttribute.cxx:84
 TLDAPAttribute.cxx:85
 TLDAPAttribute.cxx:86
 TLDAPAttribute.cxx:87
 TLDAPAttribute.cxx:88
 TLDAPAttribute.cxx:89
 TLDAPAttribute.cxx:90
 TLDAPAttribute.cxx:91
 TLDAPAttribute.cxx:92
 TLDAPAttribute.cxx:93
 TLDAPAttribute.cxx:94
 TLDAPAttribute.cxx:95
 TLDAPAttribute.cxx:96
 TLDAPAttribute.cxx:97
 TLDAPAttribute.cxx:98
 TLDAPAttribute.cxx:99
 TLDAPAttribute.cxx:100
 TLDAPAttribute.cxx:101
 TLDAPAttribute.cxx:102
 TLDAPAttribute.cxx:103
 TLDAPAttribute.cxx:104
 TLDAPAttribute.cxx:105
 TLDAPAttribute.cxx:106
 TLDAPAttribute.cxx:107
 TLDAPAttribute.cxx:108
 TLDAPAttribute.cxx:109
 TLDAPAttribute.cxx:110
 TLDAPAttribute.cxx:111
 TLDAPAttribute.cxx:112
 TLDAPAttribute.cxx:113
 TLDAPAttribute.cxx:114
 TLDAPAttribute.cxx:115
 TLDAPAttribute.cxx:116
 TLDAPAttribute.cxx:117
 TLDAPAttribute.cxx:118
 TLDAPAttribute.cxx:119
 TLDAPAttribute.cxx:120
 TLDAPAttribute.cxx:121
 TLDAPAttribute.cxx:122
 TLDAPAttribute.cxx:123
 TLDAPAttribute.cxx:124
 TLDAPAttribute.cxx:125
 TLDAPAttribute.cxx:126
 TLDAPAttribute.cxx:127
 TLDAPAttribute.cxx:128
 TLDAPAttribute.cxx:129
 TLDAPAttribute.cxx:130
 TLDAPAttribute.cxx:131
 TLDAPAttribute.cxx:132
 TLDAPAttribute.cxx:133
 TLDAPAttribute.cxx:134
 TLDAPAttribute.cxx:135
 TLDAPAttribute.cxx:136
 TLDAPAttribute.cxx:137
 TLDAPAttribute.cxx:138
 TLDAPAttribute.cxx:139
 TLDAPAttribute.cxx:140
 TLDAPAttribute.cxx:141
 TLDAPAttribute.cxx:142
 TLDAPAttribute.cxx:143
 TLDAPAttribute.cxx:144
 TLDAPAttribute.cxx:145
 TLDAPAttribute.cxx:146
 TLDAPAttribute.cxx:147