summaryrefslogtreecommitdiffstats
path: root/contrib/ldapc++/src/LDAPAttributeList.h
blob: f03275ed8fd13feacdc79e741329a18013abf5ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// $OpenLDAP$
/*
 * Copyright 2000-2022 The OpenLDAP Foundation, All Rights Reserved.
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */


#ifndef LDAP_ATTRIBUTE_LIST_H
#define LDAP_ATTRIBUTE_LIST_H

#include <ldap.h>
#include <list>
#include <string>

class LDAPAttribute;
class LDAPAsynConnection;
class LDAPMsg;

/**
 * This container class is used to store multiple LDAPAttribute-objects.
 */
class LDAPAttributeList{
    typedef std::list<LDAPAttribute> ListType;

    private :
        ListType m_attrs;

    public :
        typedef ListType::const_iterator const_iterator;
	typedef ListType::iterator iterator;


        /**
         * Copy-constructor
         */
        LDAPAttributeList(const LDAPAttributeList& al);
        
        /**
         * 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
         */
        LDAPAttributeList(const LDAPAsynConnection *ld, LDAPMessage *msg);

        /**
         * Constructs an empty list.
         */   
        LDAPAttributeList();

        /**
         * Destructor
         */
        virtual ~LDAPAttributeList();

        /**
         * @return The number of LDAPAttribute-objects that are currently
         * stored in this list.
         */
        size_t size() const;

        /**
         * @return true if there are zero LDAPAttribute-objects currently
         * stored in this list.
         */
        bool empty() const;

        /**
         * @return A iterator that points to the first element of the list.
         */
        const_iterator begin() const;
        
        /**
         * @return A iterator that points to the element after the last
         * element of the list.
         */
        const_iterator end() const;

	/**
	 * Get an Attribute by its AttributeType
	 * @param name The name of the Attribute to look for
	 * @return a pointer to the LDAPAttribute with the AttributeType 
	 *	"name" or 0, if there is no Attribute of that Type
	 */
	const LDAPAttribute* getAttributeByName(const std::string& name) const;

        /**
         * Adds one element to the end of the list.
         * @param attr The attribute to add to the list.
         */
        void addAttribute(const LDAPAttribute& attr);
        
        /**
         * Deletes all values of an Attribute for the list
         * @param type The attribute type to be deleted.
         */
        void delAttribute(const std::string& type);

        /**
         * Replace an Attribute in the List
         * @param attr The attribute to add to the list.
         */
        void replaceAttribute(const LDAPAttribute& attr);

        /**
         * Translates the list of Attributes to a 0-terminated array of
         * LDAPMod-structures as needed by the C-API
         */
        LDAPMod** toLDAPModArray() const;
        
        /**
         * This method can be used to dump the data of a LDAPResult-Object.
         * It is only useful for debugging purposes at the moment
         */
        friend std::ostream& operator << (std::ostream& s, 
					  const LDAPAttributeList& al);
};

#endif // LDAP_ATTRIBUTE_LIST_H