]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPAttrType.cpp
ecc9f207eef51f89476804f6ecd4a8c637c273c8
[openldap] / contrib / ldapc++ / src / LDAPAttrType.cpp
1 // $OpenLDAP$
2 /*
3  * Copyright 2003, OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "debug.h"
8 #include "LDAPAttrType.h"
9
10
11 LDAPAttrType::LDAPAttrType(){
12     DEBUG(LDAP_DEBUG_CONSTRUCT,
13             "LDAPAttrType::LDAPAttrType( )" << endl);
14
15     oid = string ();
16     desc = string ();
17     names = StringList ();
18     single = false;
19     usage = 0;
20 }
21
22 LDAPAttrType::LDAPAttrType (const LDAPAttrType &at){
23     DEBUG(LDAP_DEBUG_CONSTRUCT,
24             "LDAPAttrType::LDAPAttrType( )" << endl);
25
26     oid = at.oid;
27     desc = at.desc;
28     names = at.names;
29     single = at.single;
30     usage = at.usage;
31 }
32
33 LDAPAttrType::LDAPAttrType (string at_item) { 
34
35     DEBUG(LDAP_DEBUG_CONSTRUCT,
36             "LDAPAttrType::LDAPAttrType( )" << endl);
37
38     LDAPAttributeType *a;
39     int ret;
40     const char *errp;
41     a = ldap_str2attributetype (at_item.c_str(), &ret, &errp,SCHEMA_PARSE_FLAG);
42
43     if (a) {
44         this->setNames( a->at_names );
45         this->setDesc( a->at_desc );
46         this->setOid( a->at_oid );
47         this->setSingle( a->at_single_value );
48         this->setUsage( a->at_usage );
49     }
50     // else? -> error
51 }
52
53 LDAPAttrType::~LDAPAttrType() {
54     DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttrType::~LDAPAttrType()" << endl);
55 }
56
57 void LDAPAttrType::setSingle (int at_single) {
58     single = (at_single == 1);
59 }
60     
61 void LDAPAttrType::setNames (char **at_names) {
62     names = StringList (at_names);
63 }
64
65 void LDAPAttrType::setDesc (char *at_desc) {
66     desc = string ();
67     if (at_desc)
68         desc = at_desc;
69 }
70
71 void LDAPAttrType::setOid (char *at_oid) {
72     oid = string ();
73     if (at_oid)
74         oid = at_oid;
75 }
76
77 void LDAPAttrType::setUsage (int at_usage) {
78     usage = at_usage;
79 }
80
81 bool LDAPAttrType::isSingle() const {
82     return single;
83
84
85 string LDAPAttrType::getOid() const {
86     return oid;
87 }
88
89 string LDAPAttrType::getDesc() const {
90     return desc;
91 }
92
93 StringList LDAPAttrType::getNames() const {
94     return names;
95 }
96
97 string LDAPAttrType::getName() const {
98
99     if (names.empty())
100         return "";
101     else
102         return *(names.begin());
103 }
104
105 int LDAPAttrType::getUsage() const {
106     return usage;
107 }