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