Back to index

openldap  2.4.31
Public Types | Public Member Functions | Private Types | Private Attributes | Friends
LDAPAttributeList Class Reference

This container class is used to store multiple LDAPAttribute-objects. More...

#include <LDAPAttributeList.h>

Collaboration diagram for LDAPAttributeList:
Collaboration graph
[legend]

List of all members.

Public Types

typedef ListType::const_iterator const_iterator
typedef ListType::iterator iterator

Public Member Functions

 LDAPAttributeList (const LDAPAttributeList &al)
 Copy-constructor.
 LDAPAttributeList (const LDAPAsynConnection *ld, LDAPMessage *msg)
 For internal use only.
 LDAPAttributeList ()
 Constructs an empty list.
virtual ~LDAPAttributeList ()
 Destructor.
size_t size () const
bool empty () const
const_iterator begin () const
const_iterator end () const
const LDAPAttributegetAttributeByName (const std::string &name) const
 Get an Attribute by its AttributeType.
void addAttribute (const LDAPAttribute &attr)
 Adds one element to the end of the list.
void delAttribute (const std::string &type)
 Deletes all values of an Attribute for the list.
void replaceAttribute (const LDAPAttribute &attr)
 Replace an Attribute in the List.
LDAPMod ** toLDAPModArray () const
 Translates the list of Attributes to a 0-terminated array of LDAPMod-structures as needed by the C-API.

Private Types

typedef std::list< LDAPAttributeListType

Private Attributes

ListType m_attrs

Friends

std::ostream & operator<< (std::ostream &s, const LDAPAttributeList &al)
 This method can be used to dump the data of a LDAPResult-Object.

Detailed Description

This container class is used to store multiple LDAPAttribute-objects.

Definition at line 22 of file LDAPAttributeList.h.


Member Typedef Documentation

typedef ListType::const_iterator LDAPAttributeList::const_iterator

Definition at line 29 of file LDAPAttributeList.h.

typedef ListType::iterator LDAPAttributeList::iterator

Definition at line 30 of file LDAPAttributeList.h.

Definition at line 23 of file LDAPAttributeList.h.


Constructor & Destructor Documentation

Copy-constructor.

Definition at line 29 of file LDAPAttributeList.cpp.

                                                               {
    DEBUG(LDAP_DEBUG_CONSTRUCT,
            "LDAPAttributeList::LDAPAttributList(&)" << endl);
    m_attrs=al.m_attrs;
}

For internal use only.

This constructor is used by the library internally to create a list of attributes from a LDAPMessage-struct that was return by the C-API

Definition at line 35 of file LDAPAttributeList.cpp.

                         {
    DEBUG(LDAP_DEBUG_CONSTRUCT,
            "LDAPAttributeList::LDAPAttributList()" << endl);
    BerElement *ptr=0;
    char *name=ldap_first_attribute(ld->getSessionHandle(), msg, &ptr);
/*
   This code was making problems if no attribute were returned
   How am I supposed to find decoding errors? ldap_first/next_attribute
   return 0 in case of error or if there are no more attributes. In either
   case they set the LDAP* error code to 0x54 (Decoding error) ??? Strange..

   There will be some changes in the new version of the C-API so that this
   code should work in the future.
   if(name == 0){
        ber_free(ptr,0);
        ldap_memfree(name);
        throw LDAPException(ld);
    }else{
*/        BerValue **values;
        for (;name !=0;
                name=ldap_next_attribute(ld->getSessionHandle(),msg,ptr) ){
            values=ldap_get_values_len(ld->getSessionHandle(),
                    msg, name);
            this->addAttribute(LDAPAttribute(name, values));
            ldap_memfree(name);
            ldap_value_free_len(values);
        }
        ber_free(ptr,0);
//    }
}

Here is the call graph for this function:

Constructs an empty list.

Definition at line 24 of file LDAPAttributeList.cpp.

                                    {
    DEBUG(LDAP_DEBUG_CONSTRUCT,
            "LDAPAttributeList::LDAPAttributList( )" << endl);
}

Destructor.

Definition at line 67 of file LDAPAttributeList.cpp.

                                     {
    DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttributeList::~LDAPAttributList()" << endl);
}

Member Function Documentation

Adds one element to the end of the list.

Parameters:
attrThe attribute to add to the list.

Definition at line 110 of file LDAPAttributeList.cpp.

                                                             {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addAttribute()" << endl);
    DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
            "   attr:" << attr << endl);
    const std::string attrType = attr.getName();
    const std::string::size_type attrLen = attrType.size();
    std::string::size_type tmpAttrLen = 0;
    bool done=false;
    LDAPAttributeList::iterator i;
    for( i=m_attrs.begin(); i != m_attrs.end(); i++ ){
       const std::string tmpAttrType = i->getName();
       tmpAttrLen = tmpAttrType.size();
       if(tmpAttrLen == attrLen){
           if(equal(tmpAttrType.begin(), tmpAttrType.end(), attrType.begin(),
                  nocase_compare)){
              const StringList& values = attr.getValues();
              StringList::const_iterator j;
              for(j = values.begin(); j != values.end(); j++){
                  i->addValue(*j);
              }
              DEBUG(LDAP_DEBUG_TRACE,"Attribute" << i->getName() 
                     << "already present" << endl);
              done=true;
              break; // The AttributeType was already present,
                     // we are done here
           }
       }
    }
    if(! done){
       m_attrs.push_back(attr);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
A iterator that points to the first element of the list.

Definition at line 81 of file LDAPAttributeList.cpp.

                                                              {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::begin()" << endl);
    return m_attrs.begin();
}

Here is the caller graph for this function:

void LDAPAttributeList::delAttribute ( const std::string &  type)

Deletes all values of an Attribute for the list.

Parameters:
typeThe attribute type to be deleted.

Definition at line 143 of file LDAPAttributeList.cpp.

{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl);
    DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER, "   type: " << type << endl);
    LDAPAttributeList::iterator i;
    for( i = m_attrs.begin(); i != m_attrs.end(); i++){
       if(type.size() == i->getName().size()){
           if(equal(type.begin(), type.end(), i->getName().begin(),
                  nocase_compare)){
                m_attrs.erase(i);
                break;
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool LDAPAttributeList::empty ( ) const
Returns:
true if there are zero LDAPAttribute-objects currently stored in this list.

Definition at line 76 of file LDAPAttributeList.cpp.

                                   {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::empty()" << endl);
    return m_attrs.empty();
}
Returns:
A iterator that points to the element after the last element of the list.

Definition at line 86 of file LDAPAttributeList.cpp.

                                                            {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::end()" << endl);
    return m_attrs.end();
}

Get an Attribute by its AttributeType.

Parameters:
nameThe name of the Attribute to look for
Returns:
a pointer to the LDAPAttribute with the AttributeType "name" or 0, if there is no Attribute of that Type

Definition at line 91 of file LDAPAttributeList.cpp.

                                 {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getAttributeByName()" << endl);
    DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
            "   name:" << name << endl);
    LDAPAttributeList::const_iterator i;
    for( i = m_attrs.begin(); i != m_attrs.end(); i++){
       const std::string& tmpType = i->getName();
       if(name.size() == tmpType.size()){
           if(equal(name.begin(), name.end(), tmpType.begin(),
                  nocase_compare)){
              return &(*i);
              DEBUG(LDAP_DEBUG_TRACE,"    found:" << name << endl);
           }
       }
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Replace an Attribute in the List.

Parameters:
attrThe attribute to add to the list.

Definition at line 159 of file LDAPAttributeList.cpp.

{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl);
    DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
            "   attr:" << attr << endl);
    
    LDAPAttributeList::iterator i;
    this->delAttribute( attr.getName() );
    m_attrs.push_back(attr);
}

Here is the call graph for this function:

size_t LDAPAttributeList::size ( ) const
Returns:
The number of LDAPAttribute-objects that are currently stored in this list.

Definition at line 71 of file LDAPAttributeList.cpp.

                                    {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::size()" << endl);
    return m_attrs.size();
}

Translates the list of Attributes to a 0-terminated array of LDAPMod-structures as needed by the C-API.

Definition at line 170 of file LDAPAttributeList.cpp.

                                                 {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl);
    LDAPMod **ret = (LDAPMod**) malloc((m_attrs.size()+1) * sizeof(LDAPMod*));
    LDAPAttributeList::const_iterator i;
    int j=0;
    for (i=m_attrs.begin(); i!= m_attrs.end(); i++, j++){
        ret[j]=i->toLDAPMod();
    }
    ret[m_attrs.size()]=0;
    return ret;
}

Here is the caller graph for this function:


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
const LDAPAttributeList al 
) [friend]

This method can be used to dump the data of a LDAPResult-Object.

It is only useful for debugging purposes at the moment

Definition at line 182 of file LDAPAttributeList.cpp.

                                                              {
    LDAPAttributeList::const_iterator i;
    for(i=al.m_attrs.begin(); i!=al.m_attrs.end(); i++){
        s << *i << "; ";
    }
    return s;
}

Member Data Documentation

Definition at line 26 of file LDAPAttributeList.h.


The documentation for this class was generated from the following files: