1// OpenLDAP: pkg/ldap/contrib/ldapc++/src/LDAPControlSet.cpp,v 1.4.10.1 2008/04/14 23:09:26 quanah Exp 2/* 3 * Copyright 2000, OpenLDAP Foundation, All Rights Reserved. 4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file 5 */ 6 7#include "debug.h" 8#include "LDAPControlSet.h" 9 10using namespace std; 11 12LDAPControlSet::LDAPControlSet(){ 13} 14 15LDAPControlSet::LDAPControlSet(const LDAPControlSet& cs){ 16 DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet(&)" << endl); 17 data=cs.data; 18} 19 20LDAPControlSet::LDAPControlSet(LDAPControl** controls){ 21 DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet()" << endl); 22 if(controls != 0){ 23 LDAPControl** i; 24 for( i=controls; *i!=0;i++) { 25 add(LDAPCtrl(*i)); 26 } 27 } 28} 29 30LDAPControlSet::~LDAPControlSet(){ 31 DEBUG(LDAP_DEBUG_DESTROY,"LDAPControlSet::~LDAPControlSet()" << endl); 32} 33 34size_t LDAPControlSet::size() const { 35 DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::size()" << endl); 36 return data.size(); 37} 38 39bool LDAPControlSet::empty() const { 40 DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::empty()" << endl); 41 return data.empty(); 42} 43 44LDAPControlSet::const_iterator LDAPControlSet::begin() const{ 45 DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::begin()" << endl); 46 return data.begin(); 47} 48 49 50LDAPControlSet::const_iterator LDAPControlSet::end() const{ 51 DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::end()" << endl); 52 return data.end (); 53} 54 55void LDAPControlSet::add(const LDAPCtrl& ctrl){ 56 DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::add()" << endl); 57 data.push_back(ctrl); 58} 59 60LDAPControl** LDAPControlSet::toLDAPControlArray() const{ 61 DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::toLDAPControlArray()" << endl); 62 if(data.empty()){ 63 return 0; 64 }else{ 65 LDAPControl** ret= new LDAPControl*[data.size()+1]; 66 CtrlList::const_iterator i; 67 int j=0; 68 for(i=data.begin(); i!=data.end(); i++,j++){ 69 ret[j] = i->getControlStruct(); 70 } 71 ret[data.size()]=0; 72 return ret; 73 } 74} 75 76void LDAPControlSet::freeLDAPControlArray(LDAPControl **ctrl){ 77 DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::freeLDAPControlArray()" << endl); 78 if( ctrl ){ 79 for( LDAPControl **i = ctrl; *i != 0; ++i ){ 80 LDAPCtrl::freeLDAPControlStruct(*i); 81 } 82 } 83 delete[] ctrl; 84} 85