Commit dd19d21c authored by msobczak's avatar msobczak

Divided core into smaller modules, changed naming convention to lower_case in interfaces.

parent 101a218d
# $Id: Makefile.am,v 1.4 2006/11/27 09:59:32 mloskot Exp $
# $Id: Makefile.am,v 1.5 2007/03/02 09:45:18 msobczak Exp $
#
# Copyright (C) 2006, Mateusz Loskot
#
......@@ -14,15 +14,45 @@ lib@SOCI_CORE_LIBRARY_NAME@_la_LDFLAGS = \
-release @LIBTOOL_RELEASE@
lib@SOCI_CORE_LIBRARY_NAME@_la_SOURCES = \
soci.cpp
blob.cpp \
into-type.cpp \
once-temp-type.cpp \
prepare-temp-type.cpp \
procedure.cpp \
ref-counted-prepare-info.cpp \
ref-counted-statement.cpp \
row.cpp \
rowid.cpp \
session.cpp \
statement.cpp \
use-type.cpp \
values.cpp
socidir = $(includedir)/soci
soci_HEADERS = \
soci.h \
blob.h \
into-row.h \
into-type.h \
once-temp-type.h \
prepare-temp-type.h \
procedure.h \
ref-counted-prepare-info.h \
ref-counted-statement.h \
row.h \
rowid.h \
rowset.h \
session.h \
soci-backend.h \
soci-config.h \
soci-platform.h
soci-platform.h \
soci.h \
statement.h \
type-conversion.h \
type-holder.h \
type-ptr.h \
use-type.h \
values.h
EXTRA_DIST = Makefile.basic
......
COMPILER = g++
CXXFLAGS = -Wall -pedantic -Wno-long-long
OBJS = session.o statement.o row.o values.o \
into-type.o use-type.o \
blob.o rowid.o procedure.o ref-counted-prepare-info.o ref-counted-statement.o \
once-temp-type.o prepare-temp-type.o
libsoci-core.a : soci.o
libsoci-core.a : ${OBJS}
ar rv $@ $?
rm *.o
soci.o : soci.cpp
shared : ${OBJS}
${COMPILER} -fPIC -c $? ${CXXFLAGS}
${COMPILER} -shared -o libsoci-core.so ${OBJS}
rm *.o
session.o : session.cpp
${COMPILER} -c $? ${CXXFLAGS}
statement.o : statement.cpp
${COMPILER} -c $? ${CXXFLAGS}
shared : soci.cpp
${COMPILER} -fPIC -c $? ${CXXFLAGS}
${COMPILER} -shared -o libsoci-core.so soci.o
rm *.o
row.o : row.cpp
${COMPILER} -c $? ${CXXFLAGS}
values.o : values.cpp
${COMPILER} -c $? ${CXXFLAGS}
into-type.o : into-type.cpp
${COMPILER} -c $? ${CXXFLAGS}
use-type.o : use-type.cpp
${COMPILER} -c $? ${CXXFLAGS}
blob.o : blob.cpp
${COMPILER} -c $? ${CXXFLAGS}
rowid.o : rowid.cpp
${COMPILER} -c $? ${CXXFLAGS}
procedure.o : procedure.cpp
${COMPILER} -c $? ${CXXFLAGS}
ref-counted-prepare-info.o : ref-counted-prepare-info.cpp
${COMPILER} -c $? ${CXXFLAGS}
ref-counted-statement.o : ref-counted-statement.cpp
${COMPILER} -c $? ${CXXFLAGS}
once-temp-type.o : once-temp-type.cpp
${COMPILER} -c $? ${CXXFLAGS}
prepare-temp-type.o : prepare-temp-type.cpp
${COMPILER} -c $? ${CXXFLAGS}
clean :
rm -f libsoci-core.a libsoci-core.so
//
// Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "blob.h"
#include "session.h"
#include <cstddef>
using namespace soci;
blob::blob(session &s)
{
backEnd_ = s.make_blob_backend();
}
blob::~blob()
{
delete backEnd_;
}
std::size_t blob::get_len()
{
return backEnd_->get_len();
}
std::size_t blob::read(std::size_t offset, char *buf, std::size_t toRead)
{
return backEnd_->read(offset, buf, toRead);
}
std::size_t blob::write(
std::size_t offset, char const *buf, std::size_t toWrite)
{
return backEnd_->write(offset, buf, toWrite);
}
std::size_t blob::append(char const *buf, std::size_t toWrite)
{
return backEnd_->append(buf, toWrite);
}
void blob::trim(std::size_t newLen)
{
backEnd_->trim(newLen);
}
//
// Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_BLOB_H_INCLUDED
#define SOCI_BLOB_H_INCLUDED
#include "into-type.h"
#include "use-type.h"
#include "soci-backend.h"
namespace soci
{
// basic blob operations
class SOCI_DECL blob
{
public:
blob(session &s);
~blob();
std::size_t get_len();
std::size_t read(std::size_t offset, char *buf, std::size_t toRead);
std::size_t write(std::size_t offset, char const *buf,
std::size_t toWrite);
std::size_t append(char const *buf, std::size_t toWrite);
void trim(std::size_t newLen);
details::blob_backend * get_backend() { return backEnd_; }
private:
details::blob_backend *backEnd_;
};
namespace details
{
template <>
class into_type<blob > : public standard_into_type
{
public:
into_type(blob &b) : standard_into_type(&b, eXBLOB) {}
into_type(blob &b, eIndicator &ind)
: standard_into_type(&b, eXBLOB , ind) {}
};
template <>
class use_type<blob > : public standard_use_type
{
public:
use_type(blob &b, std::string const &name = std::string())
: standard_use_type(&b, eXBLOB , name) {}
use_type(blob &b, eIndicator &ind,
std::string const &name = std::string())
: standard_use_type(&b, eXBLOB , ind, name) {}
};
} // namespace details
} // namespace soci
#endif
//
// Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_INTO_ROW_H_INCLUDED
#define SOCI_INTO_ROW_H_INCLUDED
#include "into-type.h"
#include "row.h"
#include "statement.h"
namespace soci
{
namespace details
{
// Support selecting into a Row for dynamic queries
//
template <>
class into_type<soci::row> : public into_type_base // bypass the standard_into_type
{
public:
into_type(soci::row &r) : r_(r) {}
private:
// special handling for Row
virtual void define(statement_impl &st, int & /* position */)
{
st.set_row(&r_);
// actual row description is performed
// as part of the statement execute
}
virtual void pre_fetch() {}
virtual void post_fetch(bool gotData, bool /* calledFromFetch */)
{
r_.reset_get_counter();
if (gotData)
{
// this is used only to re-dispatch to derived class, if any
// (the derived class might be generated automatically by
// user conversions)
convert_from();
}
}
virtual void clean_up() {}
virtual std::size_t size() const { return 1; }
virtual void convert_from() {}
soci::row &r_;
};
} // namespace details
} // namespace soci
#endif
//
// Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "into-type.h"
#include "statement.h"
using namespace soci;
using namespace soci::details;
standard_into_type::~standard_into_type()
{
delete backEnd_;
}
void standard_into_type::define(statement_impl &st, int &position)
{
backEnd_ = st.make_into_type_backend();
backEnd_->define_by_pos(position, data_, type_);
}
void standard_into_type::pre_fetch()
{
backEnd_->pre_fetch();
}
void standard_into_type::post_fetch(bool gotData, bool calledFromFetch)
{
backEnd_->post_fetch(gotData, calledFromFetch, ind_);
if (gotData)
{
convert_from();
}
}
void standard_into_type::clean_up()
{
// backEnd_ might be NULL if IntoType<Row> was used
if (backEnd_ != NULL)
{
backEnd_->clean_up();
}
}
vector_into_type::~vector_into_type()
{
delete backEnd_;
}
void vector_into_type::define(statement_impl &st, int &position)
{
backEnd_ = st.make_vector_into_type_backend();
backEnd_->define_by_pos(position, data_, type_);
}
void vector_into_type::pre_fetch()
{
backEnd_->pre_fetch();
}
void vector_into_type::post_fetch(bool gotData, bool /* calledFromFetch */)
{
if (indVec_ != NULL && indVec_->empty() == false)
{
assert(indVec_->empty() == false);
backEnd_->post_fetch(gotData, &(*indVec_)[0]);
}
else
{
backEnd_->post_fetch(gotData, NULL);
}
if(gotData)
{
convert_from();
}
}
void vector_into_type::resize(std::size_t sz)
{
if (indVec_ != NULL)
{
indVec_->resize(sz);
}
backEnd_->resize(sz);
}
std::size_t vector_into_type::size() const
{
return backEnd_->size();
}
void vector_into_type::clean_up()
{
if (backEnd_ != NULL)
{
backEnd_->clean_up();
}
}
//
// Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_INTO_TYPE_H_INCLUDED
#define SOCI_INTO_TYPE_H_INCLUDED
#include "soci-backend.h"
#include "type-ptr.h"
#include <string>
#include <vector>
namespace soci
{
class session;
namespace details
{
class prepare_temp_type;
class standard_into_type_backend;
class vector_into_type_backend;
class statement_impl;
// this is intended to be a base class for all classes that deal with
// defining output data
class into_type_base
{
public:
virtual ~into_type_base() {}
virtual void define(statement_impl &st, int &position) = 0;
virtual void pre_fetch() = 0;
virtual void post_fetch(bool gotData, bool calledFromFetch) = 0;
virtual void clean_up() = 0;
virtual std::size_t size() const = 0; // returns the number of elements
virtual void resize(std::size_t /* sz */) {} // used for vectors only
};
// standard types
class SOCI_DECL standard_into_type : public into_type_base
{
public:
standard_into_type(void *data, eExchangeType type)
: data_(data), type_(type), ind_(NULL), backEnd_(NULL) {}
standard_into_type(void *data, eExchangeType type, eIndicator& ind)
: data_(data), type_(type), ind_(&ind), backEnd_(NULL) {}
virtual ~standard_into_type();
private:
virtual void define(statement_impl &st, int &position);
virtual void pre_fetch();
virtual void post_fetch(bool gotData, bool calledFromFetch);
virtual void clean_up();
virtual std::size_t size() const { return 1; }
// conversion hook (from base type to arbitrary user type)
virtual void convert_from() {}
void *data_;
eExchangeType type_;
eIndicator *ind_;
standard_into_type_backend *backEnd_;
};
// into type base class for vectors
class SOCI_DECL vector_into_type : public into_type_base
{
public:
vector_into_type(void *data, eExchangeType type)
: data_(data), type_(type), indVec_(NULL), backEnd_(NULL) {}
vector_into_type(void *data, eExchangeType type,
std::vector<eIndicator> &ind)
: data_(data), type_(type), indVec_(&ind), backEnd_(NULL) {}
~vector_into_type();
private:
virtual void define(statement_impl &st, int &position);
virtual void pre_fetch();
virtual void post_fetch(bool gotData, bool calledFromFetch);
virtual void clean_up();
virtual void resize(std::size_t sz);
virtual std::size_t size() const;
void *data_;
eExchangeType type_;
std::vector<eIndicator> *indVec_;
vector_into_type_backend *backEnd_;
virtual void convert_from() {}
};
// general case not implemented
template <typename T>
class into_type;
template <>
class into_type<short> : public standard_into_type
{
public:
into_type(short &s) : standard_into_type(&s, eXShort) {}
into_type(short &s, eIndicator &ind)
: standard_into_type(&s, eXShort, ind) {}
};
template <>
class into_type<std::vector<short> > : public vector_into_type
{
public:
into_type(std::vector<short> &v) : vector_into_type(&v, eXShort) {}
into_type(std::vector<short> &v, std::vector<eIndicator> &ind)
: vector_into_type(&v, eXShort, ind) {}
};
template <>
class into_type<int> : public standard_into_type
{
public:
into_type(int &i) : standard_into_type(&i, eXInteger) {}
into_type(int &i, eIndicator &ind)
: standard_into_type(&i, eXInteger, ind) {}
};
template <>
class into_type<std::vector<int> > : public vector_into_type
{
public:
into_type(std::vector<int> &v) : vector_into_type(&v, eXInteger) {}
into_type(std::vector<int> &v, std::vector<eIndicator> &ind)
: vector_into_type(&v, eXInteger, ind) {}
};
template <>
class into_type<char> : public standard_into_type
{
public:
into_type(char &c) : standard_into_type(&c, eXChar) {}
into_type(char &c, eIndicator &ind)
: standard_into_type(&c, eXChar, ind) {}
};
template <>
class into_type<std::vector<char> >: public vector_into_type
{
public:
into_type(std::vector<char> &v) : vector_into_type(&v, eXChar) {}
into_type(std::vector<char> &v, std::vector<eIndicator> &vind)
: vector_into_type(&v, eXChar, vind) {}
};
template <>
class into_type<unsigned long> : public standard_into_type
{
public:
into_type(unsigned long &ul) : standard_into_type(&ul, eXUnsignedLong) {}
into_type(unsigned long &ul, eIndicator &ind)
: standard_into_type(&ul, eXUnsignedLong, ind) {}
};
template <>
class into_type<std::vector<unsigned long> > : public vector_into_type
{
public:
into_type(std::vector<unsigned long> &v)
: vector_into_type(&v, eXUnsignedLong) {}
into_type(std::vector<unsigned long> &v, std::vector<eIndicator> &vind)
: vector_into_type(&v, eXUnsignedLong, vind) {}
};
template <>
class into_type<double> : public standard_into_type
{
public:
into_type(double &d) : standard_into_type(&d, eXDouble) {}
into_type(double &d, eIndicator &ind)
: standard_into_type(&d, eXDouble, ind) {}
};
template <>
class into_type<std::vector<double> > : public vector_into_type
{
public:
into_type(std::vector<double> &v)
: vector_into_type(&v, eXDouble) {}
into_type(std::vector<double> &v, std::vector<eIndicator> &vind)
: vector_into_type(&v, eXDouble, vind) {}
};
template <>
class into_type<char*> : public standard_into_type
{
public:
into_type(char *str, std::size_t bufSize)
: standard_into_type(&str_, eXCString), str_(str, bufSize) {}
into_type(char *str, eIndicator &ind, std::size_t bufSize)
: standard_into_type(&str_, eXCString, ind), str_(str, bufSize) {}
private:
cstring_descriptor str_;
};
// into types for char arrays (with size known at compile-time)
template <std::size_t N>
class into_type<char[N]> : public into_type<char*>
{
public:
into_type(char str[]) : into_type<char*>(str, N) {}
into_type(char str[], eIndicator &ind) : into_type<char*>(str, ind, N) {}
};
template <>
class into_type<std::string> : public standard_into_type
{
public:
into_type(std::string &s) : standard_into_type(&s, eXStdString) {}
into_type(std::string &s, eIndicator &ind)
: standard_into_type(&s, eXStdString, ind) {}
};
template <>
class into_type<std::vector<std::string> > : public vector_into_type
{
public:
into_type(std::vector<std::string>& v)
: vector_into_type(&v, eXStdString) {}
into_type(std::vector<std::string>& v, std::vector<eIndicator> &vind)
: vector_into_type(&v, eXStdString, vind) {}
};
template <>
class into_type<std::tm> : public standard_into_type
{
public:
into_type(std::tm &t) : standard_into_type(&t, eXStdTm) {}
into_type(std::tm &t, eIndicator &ind)
: standard_into_type(&t, eXStdTm, ind) {}
};
template <>
class into_type<std::vector<std::tm> > : public vector_into_type
{
public:
into_type(std::vector<std::tm>& v) : vector_into_type(&v, eXStdTm) {}
into_type(std::vector<std::tm>& v, std::vector<eIndicator> &vind)
: vector_into_type(&v, eXStdTm, vind) {}
};
} // namespace details
// the into function is a helper for defining output variables
template <typename T>
details::into_type_ptr into(T &t)
{
return details::into_type_ptr(new details::into_type<T>(t));
}
template <typename T, typename T1>
details::into_type_ptr into(T &t, T1 p1)
{
return details::into_type_ptr(new details::into_type<T>(t, p1));
}
template <typename T>
details::into_type_ptr into(T &t, std::vector<eIndicator> &indicator)
{
return details::into_type_ptr(new details::into_type<T>(t, indicator));
}
template <typename T>
details::into_type_ptr into(T &t, eIndicator &indicator)
{
return details::into_type_ptr(new details::into_type<T>(t, indicator));
}
} // namespace SOCI
#endif
//
// Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "once-temp-type.h"
#include "ref-counted-statement.h"
using namespace soci;
using namespace soci::details;
once_temp_type::once_temp_type(session &s)
: rcst_(new ref_counted_statement(s))
{
}
once_temp_type::once_temp_type(once_temp_type const &o)
:rcst_(o.rcst_)
{
rcst_->inc_ref();
}
once_temp_type & once_temp_type::operator=(once_temp_type const &o)
{
o.rcst_->inc_ref();
rcst_->dec_ref();
rcst_ = o.rcst_;
return *this;
}
once_temp_type::~once_temp_type()
{
rcst_->dec_ref();
}
once_temp_type & once_temp_type::operator,(into_type_ptr const &i)
{