Back to index

openldap  2.4.31
Public Member Functions | Private Member Functions | Private Attributes
LdifWriter Class Reference

#include <LdifWriter.h>

Collaboration diagram for LdifWriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LdifWriter (std::ostream &output, int version=0)
void writeRecord (const LDAPEntry &le)
void writeIncludeRecord (const std::string &target)

Private Member Functions

void breakline (const std::string &line, std::ostream &out)

Private Attributes

std::ostream & m_ldifstream
int m_version
bool m_addSeparator

Detailed Description

Definition at line 14 of file LdifWriter.h.


Constructor & Destructor Documentation

LdifWriter::LdifWriter ( std::ostream &  output,
int  version = 0 
)

Definition at line 14 of file LdifWriter.cpp.

                                                        :
        m_ldifstream(output), m_version(version), m_addSeparator(false)
{
    if ( version )
    {
        if ( version == 1 )
        {
            m_ldifstream << "version: " << version << std::endl;
            m_addSeparator = true;
        } else {
            std::ostringstream err;
            err << "Unsuported LDIF Version";
            throw( std::runtime_error(err.str()) );
        }
    }
    
}

Member Function Documentation

void LdifWriter::breakline ( const std::string &  line,
std::ostream &  out 
) [private]

Definition at line 90 of file LdifWriter.cpp.

{
    std::string::size_type pos = 0;
    std::string::size_type linelength = 76;
    bool first = true;
    
    if ( line.length() >= linelength )
    {
        while ( pos < line.length() )
        {
            if (! first )
            {
                out << " ";
            }
            out << line.substr(pos, linelength) << std::endl;
            pos += linelength;
            if ( first )
            {
                first = false;
                linelength--; //account for the leading space
            }
        }
    } else {
        out << line << std::endl;
    }
}

Here is the caller graph for this function:

void LdifWriter::writeIncludeRecord ( const std::string &  target)

Definition at line 62 of file LdifWriter.cpp.

{
    DEBUG(LDAP_DEBUG_TRACE, "writeIncludeRecord: " << target << std::endl);
    std::string scheme = target.substr( 0, sizeof("file:")-1 );
    
    if ( m_version == 1 )
    {
        std::ostringstream err;
        err << "\"include\" not allowed in LDIF version 1.";
        throw( std::runtime_error(err.str()) );
    }
    
    if ( m_addSeparator )
    {
        m_ldifstream << std::endl;
    } else {
        m_addSeparator = true;
    }

    m_ldifstream << "include: ";
    if ( scheme != "file:" )
    {
        m_ldifstream << "file://";
    }

    m_ldifstream << target << std::endl;
}

Definition at line 32 of file LdifWriter.cpp.

{
    std::ostringstream line;

    if ( m_addSeparator )
    {
        m_ldifstream << std::endl;
    } else {
        m_addSeparator = true;
    }

    line << "dn: " << le.getDN();
    this->breakline( line.str(), m_ldifstream );

    const LDAPAttributeList *al = le.getAttributes();
    LDAPAttributeList::const_iterator i = al->begin();
    for ( ; i != al->end(); i++ )
    {
        StringList values = i->getValues();
        StringList::const_iterator j = values.begin();
        for( ; j != values.end(); j++)
        {
            // clear output stream
            line.str("");
            line << i->getName() << ": " << *j;
            this->breakline( line.str(), m_ldifstream );
        }
    }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 26 of file LdifWriter.h.

std::ostream& LdifWriter::m_ldifstream [private]

Definition at line 24 of file LdifWriter.h.

Definition at line 25 of file LdifWriter.h.


The documentation for this class was generated from the following files: