Leosac  0.8.0
Open Source Access Control
AuditEventMaskODB.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 "core/audit/AuditFwd.hpp"
23 #include <odb/pgsql/traits.hxx>
24 #include <odb/sqlite/traits.hxx>
25 
31 namespace odb
32 {
33 // For SQLite
34 namespace sqlite
35 {
36 template <>
37 class value_traits<Leosac::Audit::EventMask, id_text>
38 {
39  public:
42  typedef details::buffer image_type;
43 
44  static void set_value(Leosac::Audit::EventMask &v, const details::buffer &b,
45  std::size_t n, bool is_null)
46  {
47  if (!is_null)
48  {
49  std::string bitset_rep(b.data(), n);
50  v = Leosac::Audit::EventMask(bitset_rep);
51  }
52  else
53  v.reset();
54  }
55 
56  static void set_image(details::buffer &b, std::size_t &n, bool &is_null,
57  const Leosac::Audit::EventMask &v)
58  {
59  is_null = false;
60  std::string bitset_rep = v.get_bitset().to_string();
61 
62  n = bitset_rep.size();
63  if (bitset_rep.length() > b.capacity())
64  b.capacity(bitset_rep.length());
65  std::memcpy(b.data(), bitset_rep.data(), bitset_rep.length());
66  }
67 };
68 }
69 
70 // For PGSql
71 namespace pgsql
72 {
73 template <>
74 class value_traits<Leosac::Audit::EventMask, id_string>
75 {
76  public:
79  typedef details::buffer image_type;
80 
81  static void set_value(Leosac::Audit::EventMask &v, const details::buffer &b,
82  std::size_t n, bool is_null)
83  {
84  if (!is_null)
85  {
86  std::string bitset_rep(b.data(), n);
87  v = Leosac::Audit::EventMask(bitset_rep);
88  }
89  else
90  v.reset();
91  }
92 
93  static void set_image(details::buffer &b, std::size_t &n, bool &is_null,
94  const Leosac::Audit::EventMask &v)
95  {
96  is_null = false;
97  std::string bitset_rep = v.get_bitset().to_string();
98 
99  n = bitset_rep.size();
100  if (bitset_rep.length() > b.capacity())
101  b.capacity(bitset_rep.length());
102  std::memcpy(b.data(), bitset_rep.data(), bitset_rep.length());
103  }
104 };
105 }
106 }
odb::pgsql::value_traits< Leosac::Audit::EventMask, id_string >::set_value
static void set_value(Leosac::Audit::EventMask &v, const details::buffer &b, std::size_t n, bool is_null)
Definition: AuditEventMaskODB.hpp:81
odb::sqlite::value_traits< Leosac::Audit::EventMask, id_text >::query_type
value_type query_type
Definition: AuditEventMaskODB.hpp:41
odb::sqlite::value_traits< Leosac::Audit::EventMask, id_text >::image_type
details::buffer image_type
Definition: AuditEventMaskODB.hpp:42
odb::sqlite::value_traits< Leosac::Audit::EventMask, id_text >::set_image
static void set_image(details::buffer &b, std::size_t &n, bool &is_null, const Leosac::Audit::EventMask &v)
Definition: AuditEventMaskODB.hpp:56
odb
Provide ODB magic to be able to store an Leosac::Audit::EventType (FlagSet) object.
Definition: AuditEventMaskODB.hpp:31
odb::sqlite::value_traits< Leosac::Audit::EventMask, id_text >::set_value
static void set_value(Leosac::Audit::EventMask &v, const details::buffer &b, std::size_t n, bool is_null)
Definition: AuditEventMaskODB.hpp:44
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
odb::pgsql::value_traits< Leosac::Audit::EventMask, id_string >::image_type
details::buffer image_type
Definition: AuditEventMaskODB.hpp:79
Leosac::Audit::EventMask
FlagSet< EventType > EventMask
Definition: AuditFwd.hpp:179
odb::sqlite::value_traits< Leosac::Audit::EventMask, id_text >::value_type
Leosac::Audit::EventMask value_type
Definition: AuditEventMaskODB.hpp:40
odb::pgsql::value_traits< Leosac::Audit::EventMask, id_string >::set_image
static void set_image(details::buffer &b, std::size_t &n, bool &is_null, const Leosac::Audit::EventMask &v)
Definition: AuditEventMaskODB.hpp:93
odb::pgsql::value_traits< Leosac::Audit::EventMask, id_string >::value_type
Leosac::Audit::EventMask value_type
Definition: AuditEventMaskODB.hpp:77
AuditFwd.hpp
odb::pgsql::value_traits< Leosac::Audit::EventMask, id_string >::query_type
value_type query_type
Definition: AuditEventMaskODB.hpp:78