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