2 * Copyright 2000-2002, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 #ifndef LDAP_ATTRIBUTE_H
8 #define LDAP_ATTRIBUTE_H
15 #include <StringList.h>
18 * Represents the name an value(s) of an Attribute
23 * Default constructor.
24 * initializes an empty object.
30 * Copies all values of an Attribute to a new one
31 * @param attr The Attribute that should be copied
33 LDAPAttribute(const LDAPAttribute& attr);
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
42 LDAPAttribute(const std::string& name, const std::string& value="");
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)
50 LDAPAttribute(const char* name, char **values);
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
59 LDAPAttribute(const std::string& name, const StringList& values);
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>
67 * unsigned long bv_len;
71 LDAPAttribute(const char* name, BerValue **values);
79 * Add a single string value(bin/char) to the Attribute
80 * @param value Value that should be added, it is copied inside the
83 void addValue(const std::string& value);
86 * Add a single binary value to the Attribute
87 * @param value The binary coded value that should be added to the
89 * @return 0 no problem <BR>
90 * -1 failure (mem. allocation problem)
92 int addValue(const BerValue *value);
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
100 * @return 0 no problem <BR>
101 * -1 failure (mem. allocation problem)
103 int setValues(char** values);
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
111 * @return 0 no problem <BR>
112 * -1 failure (mem. allocation problem)
114 int setValues(BerValue** values);
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
123 void setValues(const StringList& values);
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)
132 * 0-pointer in case of error
134 BerValue** getBerValues() const;
137 * @return The values of the array as a list of strings
139 const StringList& getValues() const;
142 * @return The number of values of the attribute
144 int getNumValues() const;
147 * @return The name(type) of the attribute
149 const std::string& getName() const ;
152 * Sets the Attribute's name (type)
153 * @param the new name of the object
155 void setName(const std::string& name);
158 * For internal use only.
160 * This method translate the attribute of the object into a
161 * LDAPMod-Structure as used by the C-API
163 LDAPMod* toLDAPMod() const ;
166 * @return true If the attribute contains non-printable attributes
168 bool isNotPrintable() const ;
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
178 friend std::ostream& operator << (std::ostream& s, const LDAPAttribute& attr);
180 #endif //#ifndef LDAP_ATTRIBUTE_H