lib: added some operator<() members to basic record objects
[barry/progweb.git] / src / ldifio.cc
blob84c08f4e9d4dc9592acd9bd75937989885fb4e35
1 ///
2 /// \file ldifio.cc
3 /// Storage, parser, and builder classes for ldif operations.
4 ///
6 /*
7 Copyright (C) 2010-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "ldifio.h"
24 namespace Barry {
26 LdifStore::LdifStore(const std::string &filename)
27 : m_ifs( new std::ifstream(filename.c_str()) )
28 , m_is(*m_ifs)
29 , m_os(*m_ofs) // yes, this is a reference to a null ptr
30 // but will never be used (see below as well)
31 , m_end_of_file(false)
32 , m_ldif("")
36 LdifStore::LdifStore(std::istream &is)
37 : m_is(is)
38 , m_os(*m_ofs)
39 , m_end_of_file(false)
40 , m_ldif("")
44 // output constructors
45 LdifStore::LdifStore(const std::string &filename,
46 const std::string &baseDN,
47 const std::string &dnattr)
48 : m_ofs( new std::ofstream(filename.c_str()) )
49 , m_is(*m_ifs)
50 , m_os(*m_ofs)
51 , m_end_of_file(false)
52 , m_ldif(baseDN)
54 m_ldif.SetDNAttr(dnattr);
57 LdifStore::LdifStore(std::ostream &os,
58 const std::string &baseDN,
59 const std::string &dnattr)
60 : m_is(*m_ifs)
61 , m_os(os)
62 , m_end_of_file(false)
63 , m_ldif(baseDN)
65 m_ldif.SetDNAttr(dnattr);
68 // storage operator
69 void LdifStore::operator() (const Contact &rec)
71 m_ldif.DumpLdif(m_os, rec);
74 // retrieval operator
75 bool LdifStore::operator() (Contact &rec, const Barry::Builder &builder)
77 if( m_end_of_file )
78 return false;
80 // there may be LDIF records in the input that generate
81 // invalid Contact records, but valid Contact records
82 // may come after.. so keep processing until end of stream
83 while( m_is ) {
84 if( m_ldif.ReadLdif(m_is, rec) )
85 return true;
88 m_end_of_file = true;
89 return false;
92 } // namespace Barry