1// OpenLDAP: pkg/ldap/contrib/ldapc++/src/LDAPModification.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
8#include "LDAPModification.h"
9#include "debug.h"
10
11using namespace std;
12
13LDAPModification::LDAPModification(const LDAPAttribute& attr, mod_op op){
14    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPModification::LDAPModification()" << endl);
15    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
16            "   attr:" << attr << endl);
17    m_attr = attr;
18    m_mod_op = op;
19}
20
21LDAPMod* LDAPModification::toLDAPMod() const  {
22    DEBUG(LDAP_DEBUG_TRACE,"LDAPModification::toLDAPMod()" << endl);
23    LDAPMod* ret=m_attr.toLDAPMod();
24
25    //The mod_op value of the LDAPMod-struct needs to be ORed with the right
26    // LDAP_MOD_* constant to preserve the BIN-flag (see CAPI-draft for
27    // explanation of the LDAPMod struct)
28    switch (m_mod_op){
29	case OP_ADD :
30	    ret->mod_op |= LDAP_MOD_ADD;
31	break;
32	case OP_DELETE :
33	    ret->mod_op |= LDAP_MOD_DELETE;
34	break;
35	case OP_REPLACE :
36	    ret->mod_op |= LDAP_MOD_REPLACE;
37	break;
38    }
39    return ret;
40}
41