GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — xplot/include/xplot/xboxed_container.hpp at master · QuantStack/xplot Expand file tree/ Copy pathxboxed_container.hppMore file actions 166 lines (133 loc) · 4.4 KB / Copy pathxboxed_container.hppFile metadata and controls166 lines (133 loc) · 4.4 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 /*************************************************************************** * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * * * * Distributed under the terms of the BSD 3-Clause License. * * * * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ #ifndef XBOXED_CONTAINER_HPP #define XBOXED_CONTAINER_HPP #include <algorithm> #include <string> #include <utility> #include <vector> #include "nlohmann/json.hpp" #include "xeus/xjson.hpp" namespace nl = nlohmann; namespace xpl { /******************************** * xboxed_container declaration * ********************************/ template <class C> class xboxed_container { public: using container_type = C; using reference = container_type&; using const_reference = const container_type&; xboxed_container() = default; ~xboxed_container() = default; xboxed_container(const xboxed_container&) = default; xboxed_container(xboxed_container&&) = default; xboxed_container& operator=(const xboxed_container&) = default; xboxed_container& operator=(xboxed_container&&) = default; xboxed_container(const_reference c); template <class T> xboxed_container(const T& c); xboxed_container(container_type&& c); xboxed_container& operator=(const_reference c); xboxed_container& operator=(container_type&& c); template <class T> xboxed_container& operator=(const T& c); operator reference() noexcept; operator const_reference() const noexcept; private: container_type m_container; }; template <class C> void to_json(nl::json& j, const xboxed_container<C>& o); template <class C> void from_json(const nl::json& j, xboxed_container<C>& o); template <class T> std::string type_to_string() noexcept; /*********************************** * xboxed_container implementation * ***********************************/ template <class C> inline xboxed_container<C>::xboxed_container(const_reference c) : m_container(c) { } template <class C> template <class T> inline xboxed_container<C>::xboxed_container(const T& c) : m_container(c.begin(), c.end()) { } template <class C> inline xboxed_container<C>::xboxed_container(container_type&& c) : m_container(std::move(c)) { } template <class C> inline xboxed_container<C>& xboxed_container<C>::operator=(const_reference c) { m_container = c; return *this; } template <class C> inline xboxed_container<C>& xboxed_container<C>::operator=(container_type&& c) { m_container = std::move(c); return *this; } template <class C> template <class T> inline xboxed_container<C>& xboxed_container<C>::operator=(const T& c) { m_container.resize(c.size()); std::copy(c.begin(), c.end(), m_container.begin()); return *this; } template <class C> inline xboxed_container<C>::operator reference() noexcept { return m_container; } template <class C> inline xboxed_container<C>::operator const_reference() const noexcept { return m_container; } template <class C> inline void to_json(nl::json& j, const xboxed_container<C>& o) { using container_type = typename xboxed_container<C>::container_type; j["values"] = container_type(o); j["type"] = type_to_string<typename container_type::value_type>(); } template <class C> inline void from_json(const nl::json& j, xboxed_container<C>& o) { using container_type = typename xboxed_container<C>::container_type; container_type& values = o; values = j.at("values").get<container_type>(); } template <> inline std::string type_to_string<double>() noexcept { return "float"; } template <> inline std::string type_to_string<std::vector<double>>() noexcept { return "float"; } template <> inline std::string type_to_string<std::string>() noexcept { return "<U5"; } } #endif |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |