metadata.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 
3 /*
4  * Copyright (c) 2020, Bjarne von Horn
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL BJARNE VON HORN BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 #pragma once
30 
31 #include <warehouse_ros/metadata.h>
32 #include <boost/variant.hpp>
33 #include <map>
35 #include <warehouse_ros_sqlite/warehouse_ros_sqlite_export.h>
36 
37 extern "C" {
38 struct sqlite3_stmt;
39 struct sqlite3;
40 }
41 
42 namespace warehouse_ros_sqlite
43 {
44 class WAREHOUSE_ROS_SQLITE_EXPORT Metadata : public warehouse_ros::Metadata
45 {
46 public:
47  using Variant = boost::variant<NullValue, std::string, double, int>;
48  void append(const std::string& name, const std::string& val) override;
49  void append(const std::string& name, const double val) override;
50  void append(const std::string& name, const int val) override;
51  void append(const std::string& name, const bool val) override;
52  std::string lookupString(const std::string& name) const override;
53  double lookupDouble(const std::string& name) const override;
54  int lookupInt(const std::string& name) const override;
55  bool lookupBool(const std::string& name) const override;
56  bool lookupField(const std::string& name) const override;
57  std::set<std::string> lookupFieldNames() const override;
58  void append(const std::string& name, sqlite3_stmt* stmt, int col);
59  const auto& data() const
60  {
61  return data_;
62  }
63  void ensureColumns(sqlite3* db, const std::string& unescaped_table_name) const;
64 
65 private:
66  // ordered map for reproducible iterating
67  std::map<std::string, Variant> data_;
68 
69  template <typename R>
70  R doLookup(const std::string& name) const;
71 };
72 
73 } // namespace warehouse_ros_sqlite
warehouse_ros_sqlite
Definition: database_connection.h:36
warehouse_ros::Metadata
warehouse_ros_sqlite::Metadata::Variant
boost::variant< NullValue, std::string, double, int > Variant
Definition: metadata.h:47
warehouse_ros_sqlite::Metadata::data
const auto & data() const
Definition: metadata.h:59
utils.h
warehouse_ros_sqlite::Metadata
Definition: metadata.h:44
metadata.h
warehouse_ros_sqlite::Metadata::data_
std::map< std::string, Variant > data_
Definition: metadata.h:67
append
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)


warehouse_ros_sqlite
Author(s): Bjarne von Horn
autogenerated on Mon Oct 14 2024 02:16:58