]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPAttributeList.h
add wrapper methods to add/replace Attributes
[openldap] / contrib / ldapc++ / src / LDAPAttributeList.h
1 /*
2  * Copyright 2000-2002, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6
7 #ifndef LDAP_ATTRIBUTE_LIST_H
8 #define LDAP_ATTRIBUTE_LIST_H
9
10 #include <ldap.h>
11 #include <list>
12 #include <string>
13
14 class LDAPAttribute;
15 class LDAPAsynConnection;
16 class LDAPMsg;
17
18 /**
19  * This container class is used to store multiple LDAPAttribute-objects.
20  */
21 class LDAPAttributeList{
22     typedef std::list<LDAPAttribute> ListType;
23
24     private :
25         ListType m_attrs;
26
27     public :
28         typedef ListType::const_iterator const_iterator;
29         typedef ListType::iterator iterator;
30
31
32         /**
33          * Copy-constructor
34          */
35         LDAPAttributeList(const LDAPAttributeList& al);
36         
37         /**
38          * For internal use only
39          *
40          * This constructor is used by the library internally to create a
41          * list of attributes from a LDAPMessage-struct that was return by
42          * the C-API
43          */
44         LDAPAttributeList(const LDAPAsynConnection *ld, LDAPMessage *msg);
45
46         /**
47          * Constructs an empty list.
48          */   
49         LDAPAttributeList();
50
51         /**
52          * Destructor
53          */
54         virtual ~LDAPAttributeList();
55
56         /**
57          * @return The number of LDAPAttribute-objects that are currently
58          * stored in this list.
59          */
60         size_t size() const;
61
62         /**
63          * @return true if there are zero LDAPAttribute-objects currently
64          * stored in this list.
65          */
66         bool empty() const;
67
68         /**
69          * @return A iterator that points to the first element of the list.
70          */
71         const_iterator begin() const;
72         
73         /**
74          * @return A iterator that points to the element after the last
75          * element of the list.
76          */
77         const_iterator end() const;
78
79         /**
80          * Get an Attribute by its AttributeType
81          * @param name The name of the Attribute to look for
82          * @return a pointer to the LDAPAttribute with the AttributeType 
83          *      "name" or 0, if there is no Attribute of that Type
84          */
85         const LDAPAttribute* getAttributeByName(const std::string& name) const;
86
87         /**
88          * Adds one element to the end of the list.
89          * @param attr The attribute to add to the list.
90          */
91         void addAttribute(const LDAPAttribute& attr);
92
93         /**
94          * Replace an Attribute in the List
95          * @param attr The attribute to add to the list.
96          */
97         void replaceAttribute(const LDAPAttribute& attr);
98
99         /**
100          * Translates the list of Attributes to a 0-terminated array of
101          * LDAPMod-structures as needed by the C-API
102          */
103         LDAPMod** toLDAPModArray() const;
104         
105         /**
106          * This method can be used to dump the data of a LDAPResult-Object.
107          * It is only useful for debugging purposes at the moment
108          */
109         friend std::ostream& operator << (std::ostream& s, 
110                                           const LDAPAttributeList& al);
111 };
112
113 #endif // LDAP_ATTRIBUTE_LIST_H
114