Back to index

openldap  2.4.31
LDAPControlSet.cpp
Go to the documentation of this file.
00001 // $OpenLDAP$
00002 /*
00003  * Copyright 2000-2012 The OpenLDAP Foundation, All Rights Reserved.
00004  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
00005  */
00006 
00007 #include "debug.h"
00008 #include "LDAPControlSet.h"
00009 
00010 using namespace std;
00011 
00012 LDAPControlSet::LDAPControlSet(){
00013 }
00014 
00015 LDAPControlSet::LDAPControlSet(const LDAPControlSet& cs){
00016     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet(&)" << endl);
00017     data=cs.data;
00018 }
00019 
00020 LDAPControlSet::LDAPControlSet(LDAPControl** controls){
00021     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet()" << endl);
00022     if(controls != 0){
00023         LDAPControl** i;
00024         for( i=controls; *i!=0;i++) {
00025             add(LDAPCtrl(*i));
00026         }
00027     }
00028 }
00029 
00030 LDAPControlSet::~LDAPControlSet(){
00031     DEBUG(LDAP_DEBUG_DESTROY,"LDAPControlSet::~LDAPControlSet()" << endl);
00032 }
00033 
00034 size_t LDAPControlSet::size() const {
00035     DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::size()" << endl);
00036     return data.size();
00037 }
00038 
00039 bool LDAPControlSet::empty() const {
00040     DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::empty()" << endl);
00041     return data.empty();
00042 }
00043 
00044 LDAPControlSet::const_iterator LDAPControlSet::begin() const{
00045     DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::begin()" << endl);
00046     return data.begin();
00047 }
00048 
00049 
00050 LDAPControlSet::const_iterator LDAPControlSet::end() const{
00051     DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::end()" << endl);
00052     return data.end ();
00053 }
00054 
00055 void LDAPControlSet::add(const LDAPCtrl& ctrl){
00056     DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::add()" << endl);
00057     data.push_back(ctrl);
00058 }
00059 
00060 LDAPControl** LDAPControlSet::toLDAPControlArray() const{
00061     DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::toLDAPControlArray()" << endl);
00062     if(data.empty()){
00063         return 0;
00064     }else{
00065         LDAPControl** ret= new LDAPControl*[data.size()+1];
00066         CtrlList::const_iterator i;
00067         int j=0;
00068         for(i=data.begin(); i!=data.end(); i++,j++){
00069             ret[j] = i->getControlStruct();
00070         }
00071         ret[data.size()]=0;
00072         return ret;
00073     }
00074 }
00075 
00076 void LDAPControlSet::freeLDAPControlArray(LDAPControl **ctrl){
00077     DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::freeLDAPControlArray()" << endl);
00078     if( ctrl ){
00079         for( LDAPControl **i = ctrl; *i != 0; ++i ){
00080            LDAPCtrl::freeLDAPControlStruct(*i);
00081        }
00082     }
00083     delete[] ctrl;
00084 }