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