13
0

Make code adhere to C++98 (WIP)

This commit is contained in:
Luciano Iam 2020-02-20 23:16:02 +01:00 committed by Robin Gareus
parent 8db9755d1e
commit 6e499e2cc5
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
13 changed files with 96 additions and 89 deletions

View File

@ -19,7 +19,7 @@
#ifndef client_context_h #ifndef client_context_h
#define client_context_h #define client_context_h
#include <unordered_set> #include <boost/unordered_set.hpp>
#include <list> #include <list>
#include "state.h" #include "state.h"
@ -48,7 +48,7 @@ class ClientContext
Client _wsi; Client _wsi;
typedef std::unordered_set<NodeState> ClientState; typedef boost::unordered_set<NodeState> ClientState;
ClientState _state; ClientState _state;
ClientOutputBuffer _output_buf; ClientOutputBuffer _output_buf;

View File

@ -187,8 +187,8 @@ WebsocketsDispatcher::strip_plugin_param_value_handler (Client client, const Nod
} }
void void
WebsocketsDispatcher::update (Client client, std::string node, WebsocketsDispatcher::update (Client client, std::string node, std::vector<uint32_t> addr,
std::initializer_list<uint32_t> addr, std::initializer_list<TypedValue> val) std::vector<TypedValue> val)
{ {
server ().update_client (client, { node, addr, val }, true); server ().update_client (client, { node, addr, val }, true);
} }

View File

@ -19,7 +19,7 @@
#ifndef websockets_dispatcher_h #ifndef websockets_dispatcher_h
#define websockets_dispatcher_h #define websockets_dispatcher_h
#include <unordered_map> #include <boost/unordered_map.hpp>
#include "component.h" #include "component.h"
#include "client.h" #include "client.h"
@ -39,7 +39,7 @@ class WebsocketsDispatcher : public SurfaceComponent
private: private:
typedef void (WebsocketsDispatcher::*DispatcherMethod) (Client, const NodeStateMessage&); typedef void (WebsocketsDispatcher::*DispatcherMethod) (Client, const NodeStateMessage&);
typedef std::unordered_map<std::string, DispatcherMethod> NodeMethodMap; typedef boost::unordered_map<std::string, DispatcherMethod> NodeMethodMap;
static NodeMethodMap _node_to_method; static NodeMethodMap _node_to_method;
@ -50,8 +50,7 @@ class WebsocketsDispatcher : public SurfaceComponent
void strip_plugin_enable_handler (Client, const NodeStateMessage&); void strip_plugin_enable_handler (Client, const NodeStateMessage&);
void strip_plugin_param_value_handler (Client, const NodeStateMessage&); void strip_plugin_param_value_handler (Client, const NodeStateMessage&);
void update (Client, std::string, std::initializer_list<uint32_t>, void update (Client, std::string, std::vector<uint32_t>, std::vector<TypedValue>);
std::initializer_list<TypedValue>);
}; };

View File

@ -164,8 +164,7 @@ ArdourFeedback::observe_strip_plugin_param_values (uint32_t strip_n,
} }
void void
ArdourFeedback::update_all (std::string node, std::initializer_list<uint32_t> addr, ArdourFeedback::update_all (std::string node, std::vector<uint32_t> addr, TypedValue val) const
TypedValue val) const
{ {
server ().update_all_clients ({ node, addr, { val }}, false); server ().update_all_clients ({ node, addr, { val }}, false);
} }

View File

@ -49,7 +49,7 @@ class ArdourFeedback : public SurfaceComponent
void observe_strip_plugin_param_values (uint32_t, uint32_t, void observe_strip_plugin_param_values (uint32_t, uint32_t,
boost::shared_ptr<ARDOUR::PluginInsert>); boost::shared_ptr<ARDOUR::PluginInsert>);
void update_all (std::string, std::initializer_list<uint32_t>, TypedValue) const; void update_all (std::string, std::vector<uint32_t>, TypedValue) const;
}; };

View File

@ -47,13 +47,13 @@ NodeStateMessage::NodeStateMessage (void *buf, size_t len)
, _write (false) , _write (false)
{ {
try { try {
std::string s { static_cast<char *>(buf), len }; std::string s (static_cast<char *>(buf), len);
std::istringstream is { s }; std::istringstream is (s);
pt::ptree root; pt::ptree root;
pt::read_json (is, root); pt::read_json (is, root);
_state = NodeState { root.get<std::string> ("node") }; _state = NodeState (root.get<std::string> ("node"));
pt::ptree addr = root.get_child ("addr", pt::ptree ()); pt::ptree addr = root.get_child ("addr", pt::ptree ());

View File

@ -25,8 +25,7 @@
using namespace Glib; using namespace Glib;
WebsocketsServer::WebsocketsServer WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface)
(ArdourSurface::ArdourWebsockets& surface)
: SurfaceComponent (surface) : SurfaceComponent (surface)
, _lws_context (0) , _lws_context (0)
{ {

View File

@ -19,7 +19,7 @@
#ifndef websockets_server_h #ifndef websockets_server_h
#define websockets_server_h #define websockets_server_h
#include <unordered_map> #include <boost/unordered_map.hpp>
#include <libwebsockets.h> #include <libwebsockets.h>
#if LWS_LIBRARY_VERSION_MAJOR < 3 #if LWS_LIBRARY_VERSION_MAJOR < 3
@ -68,10 +68,10 @@ class WebsocketsServer : public SurfaceComponent
Glib::RefPtr<Glib::IOChannel> _channel; Glib::RefPtr<Glib::IOChannel> _channel;
typedef std::unordered_map<lws_sockfd_type, LwsPollFdGlibSource> LwsPollFdGlibSourceMap; typedef boost::unordered_map<lws_sockfd_type, LwsPollFdGlibSource> LwsPollFdGlibSourceMap;
LwsPollFdGlibSourceMap _fd_ctx; LwsPollFdGlibSourceMap _fd_ctx;
typedef std::unordered_map<Client, ClientContext> ClientContextMap; typedef boost::unordered_map<Client, ClientContext> ClientContextMap;
ClientContextMap _client_ctx; ClientContextMap _client_ctx;
void add_poll_fd (struct lws_pollargs*); void add_poll_fd (struct lws_pollargs*);

View File

@ -17,28 +17,20 @@
*/ */
#include <sstream> #include <sstream>
#include <boost/unordered_set.hpp>
#include "state.h" #include "state.h"
NodeState::NodeState () NodeState::NodeState () { }
{
update_node_addr_hash ();
}
NodeState::NodeState (std::string node) NodeState::NodeState (std::string node)
: _node (node) : _node (node) { }
{
update_node_addr_hash ();
}
NodeState::NodeState (std::string node, std::initializer_list<uint32_t> addr, NodeState::NodeState (std::string node, std::vector<uint32_t> addr,
std::initializer_list<TypedValue> val) std::vector<TypedValue> val)
: _node (node) : _node (node)
, _addr (addr) , _addr (addr)
, _val (val) , _val (val) { }
{
update_node_addr_hash ();
}
std::string std::string
NodeState::debug_str () const NodeState::debug_str () const
@ -57,8 +49,6 @@ NodeState::debug_str () const
for (std::vector<TypedValue>::const_iterator it = _val.begin (); it != _val.end (); ++it) { for (std::vector<TypedValue>::const_iterator it = _val.begin (); it != _val.end (); ++it) {
s << std::endl << " val " << it->debug_str (); s << std::endl << " val " << it->debug_str ();
} }
s << std::endl << " hash = " << _node_addr_hash;
return s.str (); return s.str ();
} }
@ -79,7 +69,6 @@ void
NodeState::add_addr (uint32_t addr) NodeState::add_addr (uint32_t addr)
{ {
_addr.push_back (addr); _addr.push_back (addr);
update_node_addr_hash ();
} }
int int
@ -104,15 +93,22 @@ NodeState::add_val (TypedValue val)
_val.push_back (val); _val.push_back (val);
} }
void std::size_t
NodeState::update_node_addr_hash () NodeState::node_addr_hash () const
{ {
std::stringstream ss; std::size_t seed = 0;
ss << _node; boost::hash_combine (seed, _node);
boost::hash_combine (seed, _addr);
for (std::vector<uint32_t>::iterator it = _addr.begin (); it != _addr.end (); ++it) { return seed;
ss << "_" << *it; }
}
bool
_node_addr_hash = ss.str (); NodeState::operator== (const NodeState& other) const
{
return node_addr_hash () == other.node_addr_hash ();
}
std::size_t hash_value (const NodeState &state)
{
return state.node_addr_hash ();
} }

View File

@ -19,9 +19,10 @@
#ifndef node_state_h #ifndef node_state_h
#define node_state_h #define node_state_h
#include <vector> #include <stdint.h>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <vector>
#include "typed_value.h" #include "typed_value.h"
@ -36,7 +37,7 @@ namespace Node {
const std::string strip_plugin_enable = "strip_plugin_enable"; const std::string strip_plugin_enable = "strip_plugin_enable";
const std::string strip_plugin_param_desc = "strip_plugin_param_desc"; const std::string strip_plugin_param_desc = "strip_plugin_param_desc";
const std::string strip_plugin_param_value = "strip_plugin_param_value"; const std::string strip_plugin_param_value = "strip_plugin_param_value";
}; }
class NodeState { class NodeState {
@ -44,8 +45,8 @@ class NodeState {
NodeState (); NodeState ();
NodeState (std::string); NodeState (std::string);
NodeState (std::string, std::initializer_list<uint32_t>, NodeState (std::string, std::vector<uint32_t>,
std::initializer_list<TypedValue> = {}); std::vector<TypedValue> = std::vector<TypedValue>());
std::string debug_str () const; std::string debug_str () const;
@ -59,37 +60,18 @@ class NodeState {
TypedValue nth_val (int) const; TypedValue nth_val (int) const;
void add_val (TypedValue); void add_val (TypedValue);
std::size_t node_addr_hash () const;
bool operator== (const NodeState& other) const;
private: private:
std::string _node; std::string _node;
std::vector<uint32_t> _addr; std::vector<uint32_t> _addr;
std::vector<TypedValue> _val; std::vector<TypedValue> _val;
std::string _node_addr_hash;
void update_node_addr_hash ();
friend struct std::hash<NodeState>;
friend struct std::equal_to<NodeState>;
}; };
namespace std { std::size_t hash_value (const NodeState&);
template <>
struct hash<NodeState> {
size_t operator () (const NodeState &state) const {
// std::hash<const char*> produces a hash of the value of the
// pointer (the memory address), it does not examine the contents
// of any character array.
return std::hash<std::string>()(state._node_addr_hash);
}
};
template<>
struct equal_to<NodeState> {
bool operator() (const NodeState& lhs, const NodeState& rhs) const {
return lhs._node_addr_hash == rhs._node_addr_hash;
}
};
}
#endif // node_state_h #endif // node_state_h

View File

@ -62,7 +62,7 @@ class ArdourStrips : public SurfaceComponent
private: private:
typedef std::vector<boost::shared_ptr<ARDOUR::Stripable>> StripableVector; typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > StripableVector;
StripableVector _strips; StripableVector _strips;
}; };

View File

@ -19,11 +19,43 @@
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include <string> #include <string>
#include <boost/lexical_cast.hpp>
#include "typed_value.h" #include "typed_value.h"
#define DBL_TOLERANCE 0.001 #define DBL_TOLERANCE 0.001
TypedValue::TypedValue ()
: _type (Empty)
, _b (false)
, _i (0)
, _d (0) { }
TypedValue::TypedValue (bool value)
: _type (Bool)
, _b (value)
, _i (0)
, _d (0) { }
TypedValue::TypedValue (int value)
: _type (Int)
, _b (false)
, _i (value)
, _d (0) { }
TypedValue::TypedValue (double value)
: _type (Double)
, _b (false)
, _i (0)
, _d (value) { }
TypedValue::TypedValue (std::string value)
: _type (String)
, _b (false)
, _i (0)
, _d (0)
, _s (value) { }
TypedValue::operator TypedValue::operator
bool () const bool () const
{ {
@ -53,8 +85,8 @@ int () const
return static_cast<int>(_d); return static_cast<int>(_d);
case String: case String:
try { try {
return std::stoi (_s); return boost::lexical_cast<int> (_s);
} catch (const std::exception&) { } catch (const boost::bad_lexical_cast&) {
return 0; return 0;
} }
default: default:
@ -74,8 +106,8 @@ double () const
return static_cast<double>(_i); return static_cast<double>(_i);
case String: case String:
try { try {
return std::stod (_s); return boost::lexical_cast<double> (_s);
} catch (const std::exception&) { } catch (const boost::bad_lexical_cast&) {
return 0; return 0;
} }
default: default:
@ -92,9 +124,9 @@ std::string () const
case Bool: case Bool:
return _b ? "true" : "false"; return _b ? "true" : "false";
case Int: case Int:
return std::to_string (_i); return boost::lexical_cast<std::string> (_i);
case Double: case Double:
return std::to_string (_d); return boost::lexical_cast<std::string> (_d);
default: default:
return ""; return "";
} }

View File

@ -33,11 +33,11 @@ class TypedValue
String String
}; };
TypedValue (): _type (Empty) { } TypedValue ();
TypedValue (bool value): _type { Bool }, _b (value) { } TypedValue (bool);
TypedValue (int value): _type { Int }, _i (value) { } TypedValue (int);
TypedValue (double value): _type { Double }, _d (value) { } TypedValue (double);
TypedValue (std::string value): _type { String }, _s (value) { } TypedValue (std::string);
bool empty () const { return _type == Empty; }; bool empty () const { return _type == Empty; };
Type type () const { return _type; }; Type type () const { return _type; };
@ -55,9 +55,9 @@ class TypedValue
private: private:
Type _type; Type _type;
bool _b = false; bool _b;
int _i = 0; int _i;
double _d = 0.0; double _d;
std::string _s; std::string _s;
}; };