Mirror reflection library 0.5.13

mirror/utils/soci_factory.hpp

Go to the documentation of this file.
00001 
00011 #ifndef MIRROR_UTILS_SOCI_FACTORY_1011291729_HPP
00012 #define MIRROR_UTILS_SOCI_FACTORY_1011291729_HPP
00013 
00014 #include <mirror/config.hpp>
00015 #include <mirror/utils/sql_factory.hpp>
00016 #include <soci.h>
00017 
00018 MIRROR_NAMESPACE_BEGIN
00019 
00020 class soci_fact_data
00021 {
00022 private:
00023     typedef soci::rowset<soci::row> rowset;
00024     rowset::const_iterator const & current;
00025 
00026     template <typename T>
00027     T soci_type(T*);
00028 
00029     long soci_type(short*);
00030     long soci_type(int*);
00031     unsigned long soci_type(unsigned short*);
00032     unsigned long soci_type(unsigned int*);
00033     double soci_type(float*);
00034     // TODO: there are probably more types that need to be
00035     // re-mapped like this
00036 public:
00037     soci_fact_data(rowset::const_iterator const & iter)
00038      : current(iter)
00039     { }
00040 
00041     inline int col_count(void) const
00042     {
00043         return current->size();
00044     }
00045 
00046     inline bool is_ok(int col_index) const
00047     {
00048         return current->get_indicator(col_index) == soci::i_ok;
00049     }
00050 
00051     inline std::string get_name(int col_index) const
00052     {
00053         return current->get_properties(col_index).get_name();
00054     }
00055 
00056     inline int find_column(const std::string& name, int guess) const
00057     {
00058         std::size_t i=0, n=col_count();
00059         while(i != n)
00060         {
00061             int x = (i + guess) % n;
00062             if(get_name(x) == name) return x;
00063             ++i;
00064         }
00065         return -1;
00066     }
00067 
00068     template <typename T>
00069     inline T get_as(int col_index)
00070     {
00071         return current->get<decltype(soci_type((T*)0))>(col_index);
00072     }
00073 };
00074 
00075 typedef factory_maker<
00076     sql_fact_source,
00077     sql_fact_pool,
00078     sql_fact_enum,
00079     sql_fact_def_traits<sql_fact_helper, soci_fact_data>
00080 > soci_factory_maker;
00081 
00082 typedef factory_maker<
00083     sql_fact_source,
00084     sql_fact_pool,
00085     sql_fact_enum,
00086     sql_fact_def_traits<sql_fact_quick_helper, soci_fact_data>
00087 > soci_quick_factory_maker;
00088 
00089 MIRROR_NAMESPACE_END
00090 
00091 #endif //include guard
00092 

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.