TLDAPAttribute.cxx

Go to the documentation of this file.
00001 // @(#)root/ldap:$Id: TLDAPAttribute.cxx 36265 2010-10-11 07:17:34Z brun $
00002 // Author: Evgenia Smirnova   21/09/2001
00003 
00004 /*************************************************************************
00005  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00006  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00007  *************************************************************************/
00008 
00009 #include "TLDAPAttribute.h"
00010 #include "TObjString.h"
00011 #include "Riostream.h"
00012 
00013 
00014 ClassImp(TLDAPAttribute)
00015 
00016 //______________________________________________________________________________
00017 TLDAPAttribute::TLDAPAttribute(const char *name) : fNCount(0)
00018 {
00019    //constructor
00020    SetName(name);
00021    fValues = new TList;
00022    fValues->SetOwner();
00023 }
00024 
00025 //______________________________________________________________________________
00026 TLDAPAttribute::TLDAPAttribute(const char *name, const char *value)
00027    : fNCount(0)
00028 {
00029    // Creates an Attribute with name and value.
00030 
00031    SetName(name);
00032    fValues = new TList;
00033    fValues->SetOwner();
00034    AddValue(value);
00035 }
00036 
00037 //______________________________________________________________________________
00038 TLDAPAttribute::TLDAPAttribute(const TLDAPAttribute &attr)
00039    : TNamed(attr), fNCount(attr.fNCount)
00040 {
00041    // LDAP attribute copy ctor.
00042 
00043    fValues = new TList;
00044    fValues->SetOwner();
00045 
00046    TIter next(attr.fValues);
00047    while (TObjString *str = (TObjString*) next()) {
00048       fValues->AddLast(new TObjString(str->GetName()));
00049    }
00050 }
00051 
00052 //______________________________________________________________________________
00053 TLDAPAttribute& TLDAPAttribute::operator=(const TLDAPAttribute &attr)
00054 {
00055    // Equal operator
00056    if(this!=&attr) {
00057       TNamed::operator=(attr);
00058       fValues=attr.fValues;
00059       fNCount=attr.fNCount;
00060    } return *this;
00061 }
00062 
00063 //______________________________________________________________________________
00064 TLDAPAttribute::~TLDAPAttribute()
00065 {
00066    //destructor
00067    delete fValues;
00068 }
00069 
00070 //______________________________________________________________________________
00071 void TLDAPAttribute::AddValue(const char *value)
00072 {
00073    // Add a value to the attribute.
00074 
00075    fValues->AddLast(new TObjString(value));
00076 }
00077 
00078 //______________________________________________________________________________
00079 void TLDAPAttribute::DeleteValue(const char *value)
00080 {
00081    // Delete value by name.
00082 
00083    Int_t n = GetCount();
00084    for (Int_t i = 0; i < n; i++) {
00085       TObjString *v = (TObjString*) fValues->At(i);
00086       if (v->String().CompareTo(value) == 0) {
00087          delete fValues->Remove(v);
00088          if (fNCount > i) fNCount--;
00089          return;
00090       }
00091    }
00092 }
00093 
00094 //______________________________________________________________________________
00095 const char *TLDAPAttribute::GetValue() const
00096 {
00097    // Get next value of the attribute. Returns zero after the last value,
00098    // then returns the first value again.
00099 
00100    Int_t n = GetCount();
00101    if (n > fNCount) {
00102       return ((TObjString*)fValues->At(fNCount++))->GetName();
00103    } else {
00104       fNCount = 0;
00105       return 0;
00106    }
00107 }
00108 
00109 //_______________________________________________________________________________
00110 void TLDAPAttribute::Print(Option_t *) const
00111 {
00112    // Print an attribute.
00113 
00114    Int_t counter = GetCount();
00115    if (counter == 0) {
00116       cout << GetName() << ": " << endl;
00117    } else if (counter != 0) {
00118       for (Int_t i = 0; i < counter; i++) {
00119          cout << GetName() << ": " << GetValue() << endl;
00120       }
00121    }
00122 }
00123 
00124 //_______________________________________________________________________________
00125 LDAPMod *TLDAPAttribute::GetMod(Int_t op)
00126 {
00127    // Get "LDAPMod" structure for attribute. Returned LDAPMod must be
00128    // deleted by the user.
00129 
00130    LDAPMod *tmpMod = new LDAPMod;
00131    Int_t iCount = GetCount();
00132    char **values = new char* [iCount + 1];
00133    char *type = new char [strlen(GetName())+1];
00134    for (int i = 0; i < iCount; i++) {
00135       int nch = strlen(((TObjString*)fValues->At(i))->GetName()) + 1;
00136       values[i] = new char [nch];
00137       strlcpy(values[i], ((TObjString*)fValues->At(i))->GetName(),nch);
00138    }
00139 
00140    values[iCount] = 0;
00141    strlcpy(type, GetName(),strlen(GetName())+1);
00142    tmpMod->mod_values = values;
00143    tmpMod->mod_type = type;
00144    tmpMod->mod_op = op;
00145 
00146    return tmpMod;
00147 }

Generated on Tue Jul 5 14:45:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1