Leosac  0.8.0
Open Source Access Control
ScryptResultODB.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "tools/scrypt/Scrypt.hpp"
23 #include <odb/pgsql/traits.hxx>
24 #include <odb/sqlite/traits.hxx>
25 
33 namespace odb
34 {
35 
36 // For PGSql
37 
38 namespace pgsql
39 {
40 template <>
41 class value_traits<ScryptResult, id_string>
42 {
43  public:
46  typedef details::buffer image_type;
47 
48  static void set_value(ScryptResult &v, const details::buffer &b, std::size_t n,
49  bool is_null)
50  {
51  if (!is_null)
52  {
53  std::string str_rep(b.data(), n);
55  v = s.UnSerialize(str_rep);
56  }
57  else
58  v = ScryptResult();
59  }
60 
61  static void set_image(details::buffer &b, std::size_t &n, bool &is_null,
62  const ScryptResult &v)
63  {
64  is_null = false;
66  std::string str_rep = s.Serialize(v);
67 
68  n = str_rep.size();
69  if (str_rep.size() > b.capacity())
70  b.capacity(str_rep.length());
71  std::memcpy(b.data(), str_rep.data(), str_rep.length());
72  }
73 };
74 }
75 
76 // For SQLite
77 
78 namespace sqlite
79 {
80 template <>
81 class value_traits<ScryptResult, id_text>
82 {
83  public:
86  typedef details::buffer image_type;
87 
88  static void set_value(ScryptResult &v, const details::buffer &b, std::size_t n,
89  bool is_null)
90  {
91  if (!is_null)
92  {
93  std::string str_rep(b.data(), n);
95  v = s.UnSerialize(str_rep);
96  }
97  else
98  v = ScryptResult();
99  }
100 
101  static void set_image(details::buffer &b, std::size_t &n, bool &is_null,
102  const ScryptResult &v)
103  {
104  is_null = false;
106  std::string str_rep = s.Serialize(v);
107 
108  n = str_rep.size();
109  if (str_rep.size() > b.capacity())
110  b.capacity(str_rep.length());
111  std::memcpy(b.data(), str_rep.data(), str_rep.length());
112  }
113 };
114 }
115 }
odb::sqlite::value_traits< ScryptResult, id_text >::set_image
static void set_image(details::buffer &b, std::size_t &n, bool &is_null, const ScryptResult &v)
Definition: ScryptResultODB.hpp:101
odb::pgsql::value_traits< ScryptResult, id_string >::image_type
details::buffer image_type
Definition: ScryptResultODB.hpp:46
odb::sqlite::value_traits< ScryptResult, id_text >::value_type
ScryptResult value_type
Definition: ScryptResultODB.hpp:84
odb::pgsql::value_traits< ScryptResult, id_string >::set_image
static void set_image(details::buffer &b, std::size_t &n, bool &is_null, const ScryptResult &v)
Definition: ScryptResultODB.hpp:61
odb
Provide ODB magic to be able to store an Leosac::Audit::EventType (FlagSet) object.
Definition: AuditEventMaskODB.hpp:31
odb::pgsql::value_traits< ScryptResult, id_string >::query_type
value_type query_type
Definition: ScryptResultODB.hpp:45
odb::sqlite::value_traits< ScryptResult, id_text >::image_type
details::buffer image_type
Definition: ScryptResultODB.hpp:86
odb::sqlite::value_traits< ScryptResult, id_text >::query_type
value_type query_type
Definition: ScryptResultODB.hpp:85
StringScryptResultSerializer::UnSerialize
virtual ScryptResult UnSerialize(const std::string &in) const override
Definition: Scrypt.hpp:112
ScryptResult
Definition: Scrypt.hpp:45
odb::sqlite::value_traits< ScryptResult, id_text >::set_value
static void set_value(ScryptResult &v, const details::buffer &b, std::size_t n, bool is_null)
Definition: ScryptResultODB.hpp:88
StringScryptResultSerializer::Serialize
virtual std::string Serialize(const ScryptResult &in) const override
Definition: Scrypt.hpp:100
StringScryptResultSerializer
Definition: Scrypt.hpp:97
Scrypt.hpp
odb::pgsql::value_traits< ScryptResult, id_string >::set_value
static void set_value(ScryptResult &v, const details::buffer &b, std::size_t n, bool is_null)
Definition: ScryptResultODB.hpp:48
odb::pgsql::value_traits< ScryptResult, id_string >::value_type
ScryptResult value_type
Definition: ScryptResultODB.hpp:44