debian: added Replaces/Breaks to barrybackup-gui
[barry.git] / src / builder.cc
blobf81a3760f2e5a90a3ed169eea80011d4146ade40
1 ///
2 /// \file builder.cc
3 /// Virtual protocol packet builder wrapper
4 ///
6 /*
7 Copyright (C) 2005-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 "i18n.h"
23 #include "builder.h"
24 #include <stdexcept>
25 #include <string.h>
27 namespace Barry {
29 //////////////////////////////////////////////////////////////////////////////
30 // DBDataBuilder class
33 DBDataBuilder::DBDataBuilder(const DBData &orig)
34 : m_orig(orig)
38 DBDataBuilder::~DBDataBuilder()
42 bool DBDataBuilder::BuildRecord(DBData &data, size_t &offset,
43 const IConverter *ic)
45 if( offset == m_orig.GetOffset() ) {
46 data = m_orig;
48 else {
49 // copy the metadata
50 data.CopyMeta(m_orig);
52 // copy the buffer, to the new offset
53 if( m_orig.GetOffset() > m_orig.GetData().GetSize() )
54 throw std::logic_error(_("DBDataBuilder: offset greater than size"));
55 size_t actual = m_orig.GetData().GetSize() - m_orig.GetOffset();
56 size_t total = offset + actual;
57 unsigned char *buf = data.UseData().GetBuffer(total);
58 memcpy(buf + offset,
59 m_orig.GetData().GetData() + m_orig.GetOffset(),
60 actual);
61 data.UseData().ReleaseBuffer(total);
63 // set the new offset
64 data.SetOffset(offset);
66 return true;
69 bool DBDataBuilder::FetchRecord(DBData &data, const IConverter *ic)
71 data = m_orig;
72 return true;
75 bool DBDataBuilder::EndOfFile() const
77 return true;
80 } // namespace Barry