# ldifio.h

Go to the documentation of this file.

    00001 ///
    00002 /// \file       ldifio.h
    00003 ///             Storage, parser, and builder classes for ldif operations.
    00004 ///
    00005
    00006 /*
    00007     Copyright (C) 2010-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00008
    00009     This program is free software; you can redistribute it and/or modify
    00010     it under the terms of the GNU General Public License as published by
    00011     the Free Software Foundation; either version 2 of the License, or
    00012     (at your option) any later version.
    00013
    00014     This program is distributed in the hope that it will be useful,
    00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00017
    00018     See the GNU General Public License in the COPYING file at the
    00019     root directory of this project for more details.
    00020 */
    00021
    00022 #ifndef __BARRY_LDIFIO_H__
    00023 #define __BARRY_LDIFIO_H__
    00024
    00025 #include "dll.h"
    00026 #include "ldif.h"
    00027 #include <memory>
    00028 #include <iostream>
    00029 #include <fstream>
    00030
    00031 namespace Barry {
    00032
    00033 class Builder;
    00034
    00035 //
    00036 // LdifStore
    00037 //
    00038 /// Storage class suitable for use in a RecordParser<> or RecordBuilder<>.
    00039 /// Be sure to use the input constructors for RecordBuilder<> objects
    00040 /// and output constructors for RecordParser<> objects.
    00041 ///
    00042 /// Examples:
    00043 ///     Read contacts from an ldif stream on stdin:
    00044 ///     new RecordBuilder<Contact, LdifStore>( new LdifStore(cin) );
    00045 ///
    00046 ///     Write contacts to an ldif stream on stdout:
    00047 ///     new RecordParser<Contact, LdifStore>(
    00048 ///             new LdifStore(cout, baseDN, dnAttr) );
    00049 ///
    00050 class BXEXPORT LdifStore
    00051 {
    00052         std::auto_ptr<std::ifstream> m_ifs;
    00053         std::auto_ptr<std::ofstream> m_ofs;
    00054         std::istream &m_is;
    00055         std::ostream &m_os;
    00056         bool m_end_of_file;
    00057
    00058         Barry::ContactLdif m_ldif;
    00059
    00060 public:
    00061         // input constructors
    00062         LdifStore(const std::string &filename);
    00063         LdifStore(std::istream &is);
    00064
    00065         // output constructors
    00066         LdifStore(const std::string &filename, const std::string &baseDN,
    00067                 const std::string &dnattr);
    00068         LdifStore(std::ostream &os, const std::string &baseDN,
    00069                 const std::string &dnattr);
    00070
    00071         // storage operator
    00072         void operator() (const Contact &rec);
    00073
    00074         // retrieval operator
    00075         bool operator() (Contact &rec, const Builder &builder);
    00076 };
    00077
    00078 }
    00079
    00080 #endif
    00081