Commit 3d01a99a authored by msobczak's avatar msobczak

style

parent 03a91341
......@@ -17,7 +17,7 @@ namespace soci
{
// simple fall-back for boost::optional
template <typename T>
template <typename T>
struct type_conversion<boost::optional<T> >
{
typedef typename type_conversion<T>::base_type base_type;
......
......@@ -10,8 +10,8 @@
#include "error.h"
using namespace soci;
soci_error::soci_error(std::string const & msg)
soci_error::soci_error(std::string const & msg)
: std::runtime_error(msg)
{
}
......@@ -29,42 +29,45 @@ struct exchange_traits
// and user-defined types
typedef user_type_tag type_family;
enum { eXType =
exchange_traits<typename type_conversion<T>::base_type>::eXType };
enum // anonymous
{
eXType =
exchange_traits<typename type_conversion<T>::base_type>::eXType
};
};
template <>
struct exchange_traits<short>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXShort };
};
template <>
struct exchange_traits<int>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXInteger };
};
template <>
struct exchange_traits<char>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXChar };
};
template <>
struct exchange_traits<unsigned long>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXUnsignedLong };
};
template <>
struct exchange_traits<double>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXDouble };
};
......@@ -83,14 +86,14 @@ struct exchange_traits<char[N]>
template <>
struct exchange_traits<std::string>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXStdString };
};
template <>
struct exchange_traits<std::tm>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXStdTm };
};
......
......@@ -75,7 +75,7 @@ void vector_into_type::post_fetch(bool gotData, bool /* calledFromFetch */)
backEnd_->post_fetch(gotData, NULL);
}
if(gotData)
if (gotData)
{
convert_from_base();
}
......
......@@ -51,4 +51,3 @@ once_temp_type & once_temp_type::operator,(use_type_ptr const &u)
rcst_->exchange(u);
return *this;
}
......@@ -30,4 +30,3 @@ procedure_impl::procedure_impl(prepare_temp_type const &prep)
define_and_bind();
}
......@@ -62,7 +62,7 @@ std::size_t row::find_column(std::string const &name) const
row::~row()
{
std::size_t const hsize = holders_.size();
for(std::size_t i = 0; i != hsize; ++i)
for (std::size_t i = 0; i != hsize; ++i)
{
delete holders_[i];
delete indicators_[i];
......
......@@ -30,7 +30,7 @@ public:
typedef ptrdiff_t difference_type;
// Constructors
rowset_iterator()
: st_(0), define_(0)
{}
......@@ -38,9 +38,9 @@ public:
rowset_iterator(statement& st, T& define)
: st_(&st), define_(&define)
{
assert(0 != st_);
assert(0 != st_);
assert(0 != define_);
assert(0 != st_->get_backend());
assert(0 != st_->get_backend());
// Fetch first row to properly initialize iterator
++(*this);
......@@ -49,7 +49,7 @@ public:
// Access operators
reference operator*() const
{
{
return (*define_);
}
......@@ -67,7 +67,7 @@ public:
if (!st_->fetch())
{
// Set iterator to non-derefencable state (pass-the-end)
st_ = 0;
st_ = 0;
define_ = 0;
}
......@@ -197,14 +197,14 @@ public:
assert(0 != pimpl_);
pimpl_->decRef();
}
}
rowset& operator=(rowset const& rhs)
{
assert(0 != pimpl_);
assert(0 != rhs.pimpl_);
rhs.incRef();
rhs.incRef();
pimpl_->decRef();
pimpl_= rhs.pimpl_;
}
......@@ -222,7 +222,7 @@ public:
return pimpl_->end();
}
private:
// Pointer to implementation - the body
......
......@@ -19,8 +19,10 @@ namespace soci
{
// data types, as seen by the user
enum eDataType { eString, eChar, eDate, eDouble, eInteger,
eUnsignedLong };
enum eDataType
{
eString, eChar, eDate, eDouble, eInteger, eUnsignedLong
};
// the enum type for indicator variables
enum eIndicator { eOK, eNoData, eNull, eTruncated };
......@@ -29,9 +31,12 @@ namespace details
{
// data types, as used to describe exchange format
enum eExchangeType { eXChar, eXCString, eXStdString, eXShort, eXInteger,
eXUnsignedLong, eXDouble, eXStdTm, eXStatement,
eXRowID, eXBLOB };
enum eExchangeType
{
eXChar, eXCString, eXStdString, eXShort, eXInteger,
eXUnsignedLong, eXDouble, eXStdTm, eXStatement,
eXRowID, eXBLOB
};
// type of statement (used for optimizing statement preparation)
enum eStatementType { eOneTimeQuery, eRepeatableQuery };
......
......@@ -36,4 +36,3 @@
#endif // _MSC_VER
#endif // SOCI_CONFIG_H_INCLUDED
......@@ -31,4 +31,3 @@
#endif // _MSC_VER
#endif // SOCI_PLATFORM_H_INCLUDED
......@@ -20,13 +20,13 @@ using namespace soci;
using namespace soci::details;
void statement::exchange(into_type_ptr const &i)
{
impl_->exchange(i);
{
impl_->exchange(i);
}
void statement::exchange(use_type_ptr const &u)
{
impl_->exchange(u);
{
impl_->exchange(u);
}
statement_impl::statement_impl(session &s)
......@@ -75,7 +75,7 @@ void statement_impl::bind(values& values)
try
{
for(std::vector<details::standard_use_type*>::iterator it =
for (std::vector<details::standard_use_type*>::iterator it =
values.uses_.begin(); it != values.uses_.end(); ++it)
{
// only bind those variables which are actually
......@@ -86,7 +86,7 @@ void statement_impl::bind(values& values)
if (pos != std::string::npos)
{
const char nextChar = query_[pos + name.size()];
if(nextChar == ' ' || nextChar == ',' ||
if (nextChar == ' ' || nextChar == ',' ||
nextChar == '\0' || nextChar == ')')
{
int position = static_cast<int>(uses_.size());
......@@ -107,13 +107,13 @@ void statement_impl::bind(values& values)
cnt++;
}
}
catch(...)
catch (...)
{
for(size_t i = ++cnt; i != values.uses_.size(); ++i)
{
for (size_t i = ++cnt; i != values.uses_.size(); ++i)
{
values.add_unused(uses_[i], values.indicators_[i]);
}
throw;
throw;
}
}
......@@ -143,7 +143,7 @@ void statement_impl::exchange_for_rowset(into_type_ptr const &i)
int definePosition = 1;
p->define(*this, definePosition);
definePositionForRow_ = definePosition;
}
}
void statement_impl::exchange(use_type_ptr const &u)
{
......@@ -520,7 +520,7 @@ void statement_impl::post_fetch(bool gotData, bool calledFromFetch)
}
void statement_impl::post_use(bool gotData)
{
{
// iterate in reverse order here in case the first item
// is an UseType<Values> (since it depends on the other UseTypes)
for (std::size_t i = uses_.size(); i != 0; --i)
......@@ -581,7 +581,7 @@ void statement_impl::describe()
props.set_name(columnName);
props.set_data_type(dtype);
switch(dtype)
switch (dtype)
{
case eString:
bind_into<eString>();
......
......@@ -215,7 +215,7 @@ namespace details
template <>
struct exchange_traits<statement>
{
typedef basic_type_tag type_family;
typedef basic_type_tag type_family;
enum { eXType = eXStatement };
};
......
......@@ -23,7 +23,7 @@ struct PhonebookEntry
std::string phone;
};
struct PhonebookEntry2 : public PhonebookEntry
struct PhonebookEntry2 : public PhonebookEntry
{
};
......@@ -60,7 +60,7 @@ template<> struct type_conversion<MyInt>
i = mi.get();
ind = eOK;
}
};
};
// basic type conversion on many values (ORM)
template<> struct type_conversion<PhonebookEntry>
......@@ -81,7 +81,7 @@ template<> struct type_conversion<PhonebookEntry>
v.set("phone", pe.phone, pe.phone.empty() ? eNull : eOK);
ind = eOK;
}
};
};
// type conversion which directly calls values::indicator()
template<> struct type_conversion<PhonebookEntry2>
......@@ -103,7 +103,7 @@ template<> struct type_conversion<PhonebookEntry2>
v.set("phone", pe.phone, pe.phone.empty() ? eNull : eOK);
ind = eOK;
}
};
};
} // namespace soci
......@@ -122,7 +122,7 @@ public:
private:
void drop()
{
try { msession << "drop table soci_test"; } catch(soci_error&) {}
try { msession << "drop table soci_test"; } catch (soci_error&) {}
}
session& msession;
};
......@@ -137,7 +137,7 @@ public:
private:
void drop()
{
try { msession << "drop procedure soci_test"; } catch(soci_error&) {}
try { msession << "drop procedure soci_test"; } catch (soci_error&) {}
}
session& msession;
};
......@@ -152,14 +152,14 @@ public:
protected:
virtual std::string dropstatement()
{
{
return "drop function soci_test";
}
private:
void drop()
{
try { msession << dropstatement(); } catch(soci_error&) {}
try { msession << dropstatement(); } catch (soci_error&) {}
}
session& msession;
};
......@@ -199,7 +199,7 @@ class common_tests
{
public:
common_tests(test_context_base const &tc)
: tc_(tc),
: tc_(tc),
backEndFactory_(tc.getbackend_factory()),
connectString_(tc.get_connect_string())
{}
......@@ -215,7 +215,7 @@ public:
test5();
test6();
test7();
test8();
test8();
test9();
if (dbSupportsTransactions)
......@@ -270,7 +270,7 @@ void test1()
{
msg = e.what();
}
assert(!msg.empty());
assert(!msg.empty());
sql << "insert into soci_test (id) values (" << 123 << ")";
int id;
......@@ -325,7 +325,7 @@ void test2()
{
auto_table_creator tableCreator(tc_.table_creator_1(sql));
std::string helloSOCI("Hello, SOCI!");
sql << "insert into soci_test(str) values(:s)", use(helloSOCI);
std::string str;
......@@ -345,7 +345,7 @@ void test2()
{
auto_table_creator tableCreator(tc_.table_creator_1(sql));
int five(5);
sql << "insert into soci_test(id) values(:id)", use(five);
int i(0);
......@@ -364,7 +364,7 @@ void test2()
{
auto_table_creator tableCreator(tc_.table_creator_1(sql));
double pi(3.14159265);
sql << "insert into soci_test(d) values(:d)", use(pi);
double d(0.0);
......@@ -382,7 +382,7 @@ void test2()
nov15.tm_hour = 0;
nov15.tm_min = 0;
nov15.tm_sec = 0;
sql << "insert into soci_test(tm) values(:tm)", use(nov15);
std::tm t;
......@@ -425,7 +425,7 @@ void test2()
int id(1);
std::string str("Hello");
sql << "insert into soci_test(id, str) values(:id, :str)",
use(id), use(str);
use(id), use(str);
int i;
eIndicator ind;
......@@ -739,7 +739,7 @@ void test3()
// repeated fetch and bulk fetch of unsigned long
{
// create and populate the test table
auto_table_creator tableCreator(tc_.table_creator_1(sql));
auto_table_creator tableCreator(tc_.table_creator_1(sql));
unsigned long const rowsToTest = 100;
unsigned long ul;
......@@ -914,7 +914,7 @@ void test3()
std::cout << "test 3 passed" << std::endl;
}
// test for indicators (repeated fetch and bulk)
void test4()
{
......@@ -1884,10 +1884,10 @@ void test14()
statement st = (sql.prepare << "select * from soci_test", into(r2));
st.execute();
assert(r2.size() == 2);
assert(r2.size() == 2);
int count = 0;
while(st.fetch())
while (st.fetch())
{
++count;
assert(r2.get<std::string>("phone") == "(404)123-4567");
......@@ -1899,7 +1899,7 @@ void test14()
// test15 is like test14 but with a type_conversion instead of a row
void test15()
{
{
session sql(backEndFactory_, connectString_);
// simple conversion (between single basic type and user type)
......@@ -1942,7 +1942,7 @@ void test15()
st.execute();
int count = 0;
while(st.fetch())
while (st.fetch())
{
++count;
if (p2.name == "david")
......@@ -1955,7 +1955,7 @@ void test15()
assert(p2.phone == "(404)123-4567");
}
}
assert(count == 3);
assert(count == 3);
}
{
......@@ -1978,7 +1978,7 @@ void test15()
st.execute();
int count = 0;
while(st.fetch())
while (st.fetch())
{
++count;
if (p2.name == "david")
......@@ -1991,7 +1991,7 @@ void test15()
assert(p2.phone == "(404)123-4567");
}
}
assert(count == 3);
assert(count == 3);
}
std::cout << "test 15 passed" << std::endl;
......@@ -2139,12 +2139,12 @@ void test20()
rowset<row> rs = (sql.prepare << "select * from soci_test");
rowset<row>::const_iterator it = rs.begin();
rowset<row>::const_iterator it = rs.begin();
assert(it != rs.end());
//
// First row
//
//
row const& r1 = (*it);
// Properties
......@@ -2194,7 +2194,7 @@ void test20()
assert(r1.get<std::string>("chr") == "b");
}
//
//
// Iterate to second row
//
++it;
......@@ -2217,7 +2217,7 @@ void test20()
std::string newName = r2.get<std::string>(2);
assert(name != newName);
assert(newName == "Johny" || newName == "Robert");
if (newName == "Johny")
{
assert(std::fabs(r2.get<double>(0) - 3.14) < 0.001);
......@@ -2341,7 +2341,7 @@ void test23()
rowset<std::string> rs1 = (sql.prepare << "select str from soci_test",
into(troublemaker));
}
catch(soci_error const&)
catch (soci_error const&)
{
caught = true;
}
......@@ -2382,7 +2382,7 @@ void test24()
// Never should get here
assert(false);
}
catch(soci_error const&)
catch (soci_error const&)
{
caught = true;
}
......@@ -2394,7 +2394,7 @@ void test24()
// test25 is like test15 but with rowset and iterators use
void test25()
{
{
session sql(backEndFactory_, connectString_);
{
......@@ -2429,7 +2429,7 @@ void test25()
}
}
assert(3 == count);
assert(3 == count);
}
std::cout << "test 25 passed" << std::endl;
}
......
......@@ -15,7 +15,7 @@ namespace soci
// default traits class type_conversion, acts as pass through for Row::get()
// when no actual conversion is needed.
template <typename T>
template <typename T>
struct type_conversion
{
typedef T base_type;
......
......@@ -77,7 +77,7 @@ public:
: use_type<BASE_TYPE>(details::base_value_holder<T>::val_,
ownInd_, name),
value_(value), ind_(ownInd_) {}
conversion_use_type(T &value, eIndicator &ind, std::string const &name
conversion_use_type(T &value, eIndicator &ind, std::string const &name
= std::string())
: use_type<BASE_TYPE>(details::base_value_holder<T>::val_, ind, name),
value_(value), ind_(ind) {}
......@@ -266,12 +266,12 @@ use_type_ptr do_use(T &t, eIndicator &indicator,
// Each such specialization automatically creates a use_type and an into_type.
// This code is commented out, since it causes problems in those environments
// where std::time_t is an alias to int.
//
//
// template<>
// struct type_conversion<std::time_t>
// {
// typedef std::tm base_type;
//
//
// static void from_base(base_type const &in, eIndicator ind, std::time_t &out)
// {
// if (ind == eNull)
......@@ -280,7 +280,7 @@ use_type_ptr do_use(T &t, eIndicator &indicator,
// }
// out = mktime(&in);
// }
//
//
// static void to_base(T const &in, base_type &out, eIndicator &ind)
// {
// out = *localtime(&in);
......
......@@ -54,10 +54,10 @@ public:
virtual void bind(statement_impl &st, int &position);
std::string get_name() const {return name_;}
virtual void* get_data() {return data_;}
// conversion hook (from arbitrary user type to base type)
virtual void convert_to_base() {}
virtual void convert_from_base() {}
virtual void convert_from_base() {}
protected:
virtual void pre_use();
......
......@@ -78,7 +78,7 @@ public:
}
private:
values &v_;
values &v_;
};
} // namespace details
......
......@@ -42,4 +42,3 @@ eIndicator values::indicator(std::string const &name) const
return *indicators_[it->second];
}
}
......@@ -44,7 +44,7 @@ public:
else
{
std::ostringstream msg;
msg << "Column at position "
msg << "Column at position "
<< static_cast<unsigned long>(pos)
<< " contains NULL value and no default was provided";
throw soci_error(msg.str());
......@@ -77,7 +77,7 @@ public:
template <typename T>
T get(std::string const &name, T const &nullValue) const
{
return row_ ? row_->get<T>(name, nullValue)
return row_ ? row_->get<T>(name, nullValue)
: get_from_uses<T>(name, nullValue);
}
......@@ -101,10 +101,10 @@ public:
private:
//TODO To make values generally usable outside of TypeConversionS,
//TODO To make values generally usable outside of TypeConversionS,
// these should be reference counted smart pointers
row *row_;
std::vector<details::standard_use_type*> uses_;
row *row_;
std::vector<details::standard_use_type*> uses_;
std::map<details::use_type_base*, eIndicator*> unused_;
std::vector<eIndicator*> indicators_;
std::map<std::string, size_t> index_;
......@@ -127,7 +127,7 @@ private:
{
return get_from_uses<T>(pos->second);
}
catch(soci_error const &)
catch (soci_error const &)
{
throw soci_error("Value named " + name + " was set using"
" a different type than the one passed to get()");
......@@ -152,7 +152,7 @@ private:
{
return get_from_uses<T>(pos->second);
}
catch(soci_error const &)
catch (soci_error const &)
{
throw soci_error("Value named " + name + " was set using"
" a different type than the one passed to get()");
......@@ -180,10 +180,10 @@ private:
}
}
row& get_row()
{
row_ = new row();
return *row_;
row& get_row()
{
row_ = new row();
return *row_;
}
// this is called by Statement::bind(values)
......@@ -204,7 +204,7 @@ private:
// were not bound by the Statement
// (bound uses and indicators are deleted in Statement::clean_up())
for (std::map<details::use_type_base*, eIndicator*>::iterator pos =
unused_.begin(); pos != unused_.end(); ++pos)
unused_.begin(); pos != unused_.end(); ++pos)
{
delete pos->first;
delete pos->second;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment