]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPAttribute.h
Added ldif_countlines()
[openldap] / contrib / ldapc++ / src / LDAPAttribute.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_H
8 #define LDAP_ATTRIBUTE_H
9
10 #include<iostream>
11 #include<string>
12 #include<ldap.h>
13 #include<lber.h> 
14
15 #include <StringList.h>
16
17 /**
18  * Represents the name an value(s) of an Attribute 
19  */
20 class LDAPAttribute{
21     public :
22         /** 
23          * Default constructor.
24          * initializes an empty object.
25          */
26         LDAPAttribute();
27
28         /**
29          * Copy constructor.
30          * Copies all values of an Attribute to a new one
31          * @param attr   The Attribute that should be copied
32          */
33         LDAPAttribute(const LDAPAttribute& attr);
34
35         /**
36          * Construct an Attribute with a single string value
37          * @param name      The attribute's name (type)
38          * @param value     The string value of the attribute, if "" the
39          *                  attribute will have no values, for LDAPv3 
40          *                  this values must be UTF-8 encoded
41          */
42         LDAPAttribute(const std::string& name, const std::string& value="");
43
44         /** 
45          * Construct an attribute with multiple string values
46          * @param name      The attribute's name (type)
47          * @param values    A 0-terminated array of char*. Each char* specifies
48          *                  one value of the attribute (UTF-8 encoded)
49          */
50         LDAPAttribute(const char* name, char **values);
51         
52         /** 
53          * Construct an attribute with multiple string values
54          * @param name      The attribute's name (type)
55          * @param values    A list of strings. Each element specifies
56          *                  one value of the attribute (UTF-8 or binary 
57          *                  encoded)
58          */
59         LDAPAttribute(const std::string& name, const StringList& values);
60
61         /**
62          * Construct an attribute with multiple binary coded values
63          * @param name      The attribute's name (type)
64          * @param values    0-terminated array of binary attribute values
65          *                  The BerValue struct is declared as:<BR>
66          *                  struct berval{
67          *                      unsigned long bv_len;
68          *                      char *bv_val;
69          *                  } BerValue;
70          */         
71         LDAPAttribute(const char* name, BerValue **values);
72         
73         /**
74          * Destructor
75          */
76         ~LDAPAttribute();
77
78         /**
79          * Add a single string value(bin/char) to the Attribute
80          * @param value Value that should be added, it is copied inside the
81          *              object
82          */
83         void addValue(const std::string& value);
84
85         /**
86          * Add a single binary value to the Attribute
87          * @param value The binary coded value that should be added to the
88          *              Attribute.
89          * @return  0  no problem <BR>
90          *          -1 failure (mem. allocation problem)
91          */
92         int addValue(const BerValue *value);
93
94         /**
95          * Set the values of the attribute. If the object contains some values
96          * already, they are deleted
97          * @param values    0-terminated array of char*, each char* 
98          *                  representing a string value to add to the entry
99          * 
100          * @return  0  no problem <BR>
101          *          -1 failure (mem. allocation problem)
102          */
103         int setValues(char** values);
104
105         /**
106          * Set the values of the attribute. If the object does already contain
107          * some values, they will be deleted
108          * @param values    0-terminated array of BerValue*, each BerValue
109          *                  representing a binary value to add to the entry
110          * 
111          * @return  0  no problem <BR>
112          *          -1 failure (mem. allocation problem)
113          */
114         int setValues(BerValue** values);
115
116         /**
117          * Set the values of the attribute. If the object does already contain
118          * some values, they will be deleted
119          * @param values    A list of string-Objects. Each string is 
120          *                  representing a string or binary value to add to
121          *                  the entry
122          */
123         void setValues(const StringList& values); 
124
125         /**
126          * For interal use only.
127          * This method is used to translate the values of the Attribute to
128          * 0-terminated Array of BerValue-structs as used by the C-API
129          * @return  The Values of the Attribute as an 0-terminated Array of 
130          *          BerValue* (is dynamically allocated, delete it after usage) 
131          *          <BR>
132          *          0-pointer in case of error
133          */
134         BerValue** getBerValues() const;
135
136         /**
137          * @return The values of the array as a list of strings
138          */
139         const StringList& getValues() const;
140         
141         /**
142          * @return The number of values of the attribute
143          */
144         int getNumValues() const;
145
146         /**
147          * @return The name(type) of the attribute
148          */
149         const std::string& getName() const ;
150
151         /**
152          * Sets the Attribute's name (type) 
153          * @param the new name of the object  
154          */
155         void setName(const std::string& name);
156
157         /**
158          * For internal use only.
159          *
160          * This method translate the attribute of the object into a
161          * LDAPMod-Structure as used by the C-API
162          */
163         LDAPMod* toLDAPMod() const ;
164
165         /**
166          * @return true If the attribute contains non-printable attributes
167          */
168         bool isNotPrintable() const ;
169
170     private :
171         std::string m_name;
172         StringList m_values;
173
174     /**
175      * This method can be used to dump the data of a LDAPResult-Object.
176      * It is only useful for debugging purposes at the moment
177      */
178     friend std::ostream& operator << (std::ostream& s, const LDAPAttribute& attr);
179 };
180 #endif //#ifndef LDAP_ATTRIBUTE_H