HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Person.h
Go to the documentation of this file.
1 #ifndef PERSON
2 #define PERSON
3 
4 #include <string>
5 #include <Poco/Data/TypeHandler.h>
6 #include <Poco/Data/AbstractExtractor.h>
7 #include <Poco/Data/AbstractBinder.h>
8 #include <Poco/Data/AbstractPreparation.h>
9 
10 using namespace Poco::Data;
11 
12 struct Person {
13  int id;
14  std::string name;
15 public:
16  Person():id(0),name("") {}
17  Person(int Id,const std::string& Name):id(Id),name(Name){}
18 
19  bool operator==(const Person& other) const {
20  return name == other.name;
21  }
22 
23  bool operator < (const Person& p) const {
24  if (this->name < p.name)
25  return true;
26  return false;
27  }
28 };
29 
30 namespace Poco {
31 namespace Data {
32 
33 template <>
34 class TypeHandler<Person>
35 {
36 public:
37  static void bind(std::size_t pos, const Person& obj, Poco::Data::AbstractBinder* pBinder)
38  {
39  // the table is defined as person (id int, name VARCHAR)
40  poco_assert_dbg (pBinder != 0);
41  pBinder->bind(pos++, obj.id);
42  pBinder->bind(pos++, obj.name);
43  }
44 
45  static void prepare(std::size_t pos, const Person& obj, Poco::Data::AbstractPreparation* pPrepare)
46  {
47  // the table is defined as person (id int, name VARCHAR)
48  poco_assert_dbg (pPrepare != 0);
49  pPrepare->prepare(pos++, obj.id);
50  pPrepare->prepare(pos++, obj.name);
51  }
52 
53  static std::size_t size()
54  {
55  return 2;
56  }
57 
58  static void extract(std::size_t pos, Person& obj, const Person& defVal, Poco::Data::AbstractExtractor* pExt)
59  {
60  poco_assert_dbg (pExt != 0);
61  if (!pExt->extract(pos++, obj.id))
62  obj.name = defVal.id;
63  if (!pExt->extract(pos++, obj.name))
64  obj.name = defVal.name;
65  }
66 
67 private:
68  TypeHandler();
69  ~TypeHandler();
70  TypeHandler(const TypeHandler&);
71  TypeHandler& operator=(const TypeHandler&);
72 };
73 
74 }
75 }
76 
77 #endif