Savarese Software Research Corporation
database/types.h File Reference

This header defines macros for generating database row objects. More...

#include <ssrc/wispers/utility/CTypeWrapper.h>
#include <ssrc/wisp/utility/wisp_struct.h>
#include <boost/preprocessor/repetition.hpp>
#include <cstdint>
#include <climits>
#include <string>
#include <stdexcept>
#include <sqlite3.h>
Include dependency graph for database/types.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  detail::sqlite3_init
struct  detail::sqlite3_stmt_initializer
struct  detail::sqlite3_stmt_init
struct  detail::sqlite3_stmt_delete
class  DatabaseException
struct  detail::sqlite3_delete
class  ResultSet
struct  detail::is_basic_type< T >
struct  detail::ResultSetValueTraits< T, true >
struct  detail::ResultSetValueTraits< T, false >

Namespaces

namespace  detail

Defines

#define WSPR_DB_MAX_PARAMETERS   21
#define WSPR_DB_VALUES_ARG(z, i, _)   BOOST_PP_COMMA_IF(i) value<V ## i>(i)
#define WSPR_DB_VALUES(z, i, _)
#define WSPR_DB_VALUES_ARG(z, i, _)   BOOST_PP_COMMA_IF(i) typename tuple_element<i,T>::type
#define WSPR_DB_VALUES(z, i, _)
#define __BASIC_TYPES   (std::string)(int)(unsigned int)(std::int16_t)(std::uint16_t)(bool)(std::int64_t)(std::uint64_t)(long)(unsigned long)(double)(blob_type)
#define __IS_BASIC(r, data, type)
#define __WSPR_DB_INIT_RESULT_SET(r, rs, i, arg)   BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 1, arg)(std::move(rs.value<NS_SSRC_WSPR_DATABASE::detail::ResultSetValueTraits<BOOST_PP_TUPLE_ELEM(2, 0, arg), NS_SSRC_WSPR_DATABASE::detail::is_basic_type<BOOST_PP_TUPLE_ELEM(2, 0, arg)>::value >::db_value_type>(i)))
#define __WSPR_DB_BIND_ROW(r, data, i, arg)   BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 1, arg)
#define __WSPR_DB_LOAD_ROW   __WSPR_DB_BIND_ROW
#define __WSPR_DB_ROW_ELEMENT(r, name, i, arg)
#define __WSPR_DB_ROW_KEY(r, name, i, arg)
#define __WSPR_DB_ROW_IS_PRIMARY_KEY_CONDITION(r, column, i, arg)   BOOST_PP_EXPR_IF(i, ||) (column == arg)
#define __WSPR_DB_ROW_IS_PRIMARY_KEY(r, name, arg)   template<> inline bool name::is_primary_key<arg>() { return true; }
#define __WSPR_DB_RETURN_COLUMN_NAME(r, data, i, arg)   case i: return BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, arg)); break;
#define __WSPR_DB_ROW_PRIMARY_KEY_ELEMENT_TYPES(r, member_sequence, i, arg)   BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_SEQ_ELEM(arg, member_sequence))
#define __WSPR_DB_ROW_PRIMARY_KEY_ELEMENT_REF_TYPES(r, member_sequence, i, arg)   BOOST_PP_COMMA_IF(i) const BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_SEQ_ELEM(arg, member_sequence))&
#define __WSPR_DB_ROW_PRIMARY_KEY_TYPE(member_sequence, key_sequence)
#define __WSPR_DB_ROW_PRIMARY_KEY_REF_TYPE(member_sequence, key_sequence)
#define __WSPR_DB_ROW_PRIMARY_KEY_ELEMENTS(r, member_sequence, i, arg)   BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 1, BOOST_PP_SEQ_ELEM(arg, member_sequence))
#define __WSPR_DB_ROW_PRIMARY_KEY_BIND_PARAM(z, i, key)   BOOST_PP_COMMA_IF(i) std::get<i>(key)
#define __WSPR_DB_ROW_PRIMARY_KEY_BIND_PARAM_OFFSET(z, i, key)   .bind(offset + i + 1, std::get<i>(key))
#define __WSPR_DB_ROW_CONST_UINT(z, i, _)   BOOST_PP_COMMA_IF(i) const unsigned int
#define __WSPR_DB_ROW_PRIMARY_KEY_INDEX(z, _, i, arg)   BOOST_PP_COMMA_IF(i) arg
#define __WSPR_DB_ROW_WITH_KEY(name, member_sequence, key_sequence)
#define WSPR_DB_ROW_WITH_KEY(name, member_sequence, key_sequence)   __WSPR_DB_ROW_WITH_KEY(name, member_sequence, key_sequence)
#define __WSPR_DB_ROW_MEMBER_INDEX_SEQ(r, data, i, arg)   (i)
#define __WSPR_DB_ROW_ALL_KEYS_SEQ(member_sequence)   BOOST_PP_SEQ_FOR_EACH_I(__WSPR_DB_ROW_MEMBER_INDEX_SEQ, _, member_sequence)
#define WSPR_DB_ROW(name, member_sequence)   __WSPR_DB_ROW_WITH_KEY(name, member_sequence, __WSPR_DB_ROW_ALL_KEYS_SEQ(member_sequence))

Typedefs

typedef CTypeWrapper
< SQLite3::sqlite3, int,
sqlite3_init, sqlite3_delete > 
detail::sqlite3_ptr
typedef CTypeWrapper
< SQLite3::sqlite3_stmt, int,
sqlite3_stmt_init,
sqlite3_stmt_delete > 
detail::sqlite3_stmt_ptr
typedef std::pair< const void
*, unsigned int > 
blob_type
typedef boost::shared_ptr
< ResultSet
result_set_ptr

Functions

int detail::step (const sqlite3_stmt_ptr &statement) SSRC_DECL_THROW(DatabaseException)
template<typename T >
value (const ResultSet &result_set, const unsigned int index)
template<typename T >
values (const ResultSet &result_set)
template<>
std::int16_t ResultSet::value< std::int16_t > (unsigned int index) const
template<>
std::uint16_t ResultSet::value< std::uint16_t > (unsigned int index) const
template<>
std::int64_t ResultSet::value< std::int64_t > (unsigned int index) const
template<>
std::uint64_t ResultSet::value< std::uint64_t > (unsigned int index) const
template<>
string values< string > (const ResultSet &result_set)
template<>
int values< int > (const ResultSet &result_set)
template<>
unsigned int values< unsigned int > (const ResultSet &result_set)
template<>
std::int16_t values< std::int16_t > (const ResultSet &result_set)
template<>
std::uint16_t values< std::uint16_t > (const ResultSet &result_set)
template<>
bool values< bool > (const ResultSet &result_set)
template<>
std::int64_t values< std::int64_t > (const ResultSet &result_set)
template<>
std::uint64_t values< std::uint64_t > (const ResultSet &result_set)
template<>
long values< long > (const ResultSet &result_set)
template<>
unsigned long values< unsigned long > (const ResultSet &result_set)
template<>
double values< double > (const ResultSet &result_set)
template<>
blob_type values< blob_type > (const ResultSet &result_set)

Detailed Description

This header defines macros for generating database row objects.

Definition in file database/types.h.


Define Documentation

#define __BASIC_TYPES   (std::string)(int)(unsigned int)(std::int16_t)(std::uint16_t)(bool)(std::int64_t)(std::uint64_t)(long)(unsigned long)(double)(blob_type)

Definition at line 430 of file database/types.h.

#define __IS_BASIC (   r,
  data,
  type 
)
Value:
template<> struct is_basic_type<type> { \
    static const bool value = true;  \
  };

Definition at line 437 of file database/types.h.

#define __WSPR_DB_BIND_ROW (   r,
  data,
  i,
  arg 
)    BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 1, arg)

Definition at line 466 of file database/types.h.

#define __WSPR_DB_INIT_RESULT_SET (   r,
  rs,
  i,
  arg 
)    BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 1, arg)(std::move(rs.value<NS_SSRC_WSPR_DATABASE::detail::ResultSetValueTraits<BOOST_PP_TUPLE_ELEM(2, 0, arg), NS_SSRC_WSPR_DATABASE::detail::is_basic_type<BOOST_PP_TUPLE_ELEM(2, 0, arg)>::value >::db_value_type>(i)))

Definition at line 463 of file database/types.h.

Definition at line 469 of file database/types.h.

#define __WSPR_DB_RETURN_COLUMN_NAME (   r,
  data,
  i,
  arg 
)    case i: return BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, arg)); break;

Definition at line 493 of file database/types.h.

#define __WSPR_DB_ROW_ALL_KEYS_SEQ (   member_sequence)    BOOST_PP_SEQ_FOR_EACH_I(__WSPR_DB_ROW_MEMBER_INDEX_SEQ, _, member_sequence)

Definition at line 597 of file database/types.h.

#define __WSPR_DB_ROW_CONST_UINT (   z,
  i,
 
)    BOOST_PP_COMMA_IF(i) const unsigned int

Definition at line 519 of file database/types.h.

#define __WSPR_DB_ROW_ELEMENT (   r,
  name,
  i,
  arg 
)
Value:
template<> struct name::Element<i> {                                  \
    typedef BOOST_PP_TUPLE_ELEM(2, 0, arg) type;                        \
  };                                                                    \
  template<> inline const name::Element<i>::type & name::get<i>() const { \
    return BOOST_PP_TUPLE_ELEM(2, 1, arg);                              \
  }                                                                     \
  template<> inline std::string name::column_name<i>() {        \
    return BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, arg));          \
  }

Definition at line 471 of file database/types.h.

#define __WSPR_DB_ROW_IS_PRIMARY_KEY (   r,
  name,
  arg 
)    template<> inline bool name::is_primary_key<arg>() { return true; }

Definition at line 490 of file database/types.h.

#define __WSPR_DB_ROW_IS_PRIMARY_KEY_CONDITION (   r,
  column,
  i,
  arg 
)    BOOST_PP_EXPR_IF(i, ||) (column == arg)

Definition at line 487 of file database/types.h.

#define __WSPR_DB_ROW_KEY (   r,
  name,
  i,
  arg 
)
Value:
template<> struct name::Key<i> {                                      \
    static const unsigned int column = arg;                             \
  };

Definition at line 482 of file database/types.h.

#define __WSPR_DB_ROW_MEMBER_INDEX_SEQ (   r,
  data,
  i,
  arg 
)    (i)

Definition at line 595 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_BIND_PARAM (   z,
  i,
  key 
)    BOOST_PP_COMMA_IF(i) std::get<i>(key)

Definition at line 513 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_BIND_PARAM_OFFSET (   z,
  i,
  key 
)    .bind(offset + i + 1, std::get<i>(key))

Definition at line 516 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_ELEMENT_REF_TYPES (   r,
  member_sequence,
  i,
  arg 
)    BOOST_PP_COMMA_IF(i) const BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_SEQ_ELEM(arg, member_sequence))&

Definition at line 499 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_ELEMENT_TYPES (   r,
  member_sequence,
  i,
  arg 
)    BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_SEQ_ELEM(arg, member_sequence))

Definition at line 496 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_ELEMENTS (   r,
  member_sequence,
  i,
  arg 
)    BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2, 1, BOOST_PP_SEQ_ELEM(arg, member_sequence))

Definition at line 510 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_INDEX (   z,
  _,
  i,
  arg 
)    BOOST_PP_COMMA_IF(i) arg

Definition at line 522 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_REF_TYPE (   member_sequence,
  key_sequence 
)
Value:
BOOST_PP_IIF(BOOST_PP_EQUAL(1, BOOST_PP_SEQ_SIZE(key_sequence)),       \
               const BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_SEQ_ELEM(BOOST_PP_SEQ_ELEM(0, key_sequence), member_sequence))&, primary_key_tie_type)

Definition at line 506 of file database/types.h.

#define __WSPR_DB_ROW_PRIMARY_KEY_TYPE (   member_sequence,
  key_sequence 
)
Value:
BOOST_PP_IIF(BOOST_PP_EQUAL(1, BOOST_PP_SEQ_SIZE(key_sequence)),       \
               BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_SEQ_ELEM(BOOST_PP_SEQ_ELEM(0, key_sequence), member_sequence)), primary_key_tuple_type)

Definition at line 502 of file database/types.h.

#define __WSPR_DB_ROW_WITH_KEY (   name,
  member_sequence,
  key_sequence 
)

Definition at line 525 of file database/types.h.

#define WSPR_DB_MAX_PARAMETERS   21

Definition at line 27 of file database/types.h.

#define WSPR_DB_ROW (   name,
  member_sequence 
)    __WSPR_DB_ROW_WITH_KEY(name, member_sequence, __WSPR_DB_ROW_ALL_KEYS_SEQ(member_sequence))

Definition at line 600 of file database/types.h.

#define WSPR_DB_ROW_WITH_KEY (   name,
  member_sequence,
  key_sequence 
)    __WSPR_DB_ROW_WITH_KEY(name, member_sequence, key_sequence)

Definition at line 592 of file database/types.h.

#define WSPR_DB_VALUES (   z,
  i,
 
)
Value:
template<BOOST_PP_ENUM_PARAMS(i, typename V)>                         \
  std::tuple<BOOST_PP_ENUM_PARAMS(i, V)> values() const {     \
    return std::make_tuple<BOOST_PP_ENUM_PARAMS(i, V)>(BOOST_PP_REPEAT(i, WSPR_DB_VALUES_ARG, _)); \
  }

Definition at line 343 of file database/types.h.

#define WSPR_DB_VALUES (   z,
  i,
 
)
Value:
template<typename T> struct Values<T, i> {                            \
    static T values(const ResultSet & result_set) {                     \
      return result_set.values<BOOST_PP_REPEAT(i, WSPR_DB_VALUES_ARG, _)>(); \
    }                                                                   \
  };

Definition at line 343 of file database/types.h.

#define WSPR_DB_VALUES_ARG (   z,
  i,
 
)    BOOST_PP_COMMA_IF(i) value<V ## i>(i)

Definition at line 340 of file database/types.h.

#define WSPR_DB_VALUES_ARG (   z,
  i,
 
)    BOOST_PP_COMMA_IF(i) typename tuple_element<i,T>::type

Definition at line 340 of file database/types.h.


Typedef Documentation

typedef std::pair<const void *, unsigned int> blob_type

Definition at line 165 of file database/types.h.

typedef boost::shared_ptr<ResultSet> result_set_ptr

Definition at line 420 of file database/types.h.


Function Documentation

template<>
std::int16_t ResultSet::value< std::int16_t > ( unsigned int  index) const [inline]

Definition at line 287 of file database/types.h.

template<>
std::int64_t ResultSet::value< std::int64_t > ( unsigned int  index) const [inline]

Definition at line 301 of file database/types.h.

template<>
std::uint16_t ResultSet::value< std::uint16_t > ( unsigned int  index) const [inline]

Definition at line 292 of file database/types.h.

template<>
std::uint64_t ResultSet::value< std::uint64_t > ( unsigned int  index) const [inline]

Definition at line 306 of file database/types.h.

template<typename T >
T values ( const ResultSet result_set) [inline]

Definition at line 358 of file database/types.h.

References value().

Referenced by set_uid_to_login().

template<>
blob_type values< blob_type > ( const ResultSet result_set) [inline]

Definition at line 416 of file database/types.h.

template<>
bool values< bool > ( const ResultSet result_set) [inline]

Definition at line 386 of file database/types.h.

template<>
double values< double > ( const ResultSet result_set) [inline]

Definition at line 411 of file database/types.h.

template<>
int values< int > ( const ResultSet result_set) [inline]

Definition at line 367 of file database/types.h.

template<>
long values< long > ( const ResultSet result_set) [inline]

Definition at line 401 of file database/types.h.

template<>
std::int16_t values< std::int16_t > ( const ResultSet result_set) [inline]

Definition at line 377 of file database/types.h.

template<>
std::int64_t values< std::int64_t > ( const ResultSet result_set) [inline]

Definition at line 391 of file database/types.h.

template<>
std::uint16_t values< std::uint16_t > ( const ResultSet result_set) [inline]

Definition at line 382 of file database/types.h.

template<>
std::uint64_t values< std::uint64_t > ( const ResultSet result_set) [inline]

Definition at line 396 of file database/types.h.

template<>
string values< string > ( const ResultSet result_set) [inline]

Definition at line 363 of file database/types.h.

template<>
unsigned int values< unsigned int > ( const ResultSet result_set) [inline]

Definition at line 372 of file database/types.h.

template<>
unsigned long values< unsigned long > ( const ResultSet result_set) [inline]

Definition at line 406 of file database/types.h.


Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.