summaryrefslogtreecommitdiff
path: root/libs/surfaces
diff options
context:
space:
mode:
authorLuciano Iam <lucianito@gmail.com>2020-02-20 23:16:02 +0100
committerRobin Gareus <robin@gareus.org>2020-02-22 23:10:24 +0100
commit6e499e2cc5d2e1566145ac3719c9be9ca67d1bea (patch)
treebdbc0ee49388a2d82b172082c2c93d00ff5108b9 /libs/surfaces
parent8db9755d1e075f22275286e94b37af311c6d489f (diff)
Make code adhere to C++98 (WIP)
Diffstat (limited to 'libs/surfaces')
-rw-r--r--libs/surfaces/websockets/client.h4
-rw-r--r--libs/surfaces/websockets/dispatcher.cc4
-rw-r--r--libs/surfaces/websockets/dispatcher.h7
-rw-r--r--libs/surfaces/websockets/feedback.cc3
-rw-r--r--libs/surfaces/websockets/feedback.h2
-rw-r--r--libs/surfaces/websockets/message.cc6
-rw-r--r--libs/surfaces/websockets/server.cc3
-rw-r--r--libs/surfaces/websockets/server.h6
-rw-r--r--libs/surfaces/websockets/state.cc46
-rw-r--r--libs/surfaces/websockets/state.h38
-rw-r--r--libs/surfaces/websockets/strips.h2
-rw-r--r--libs/surfaces/websockets/typed_value.cc44
-rw-r--r--libs/surfaces/websockets/typed_value.h16
13 files changed, 94 insertions, 87 deletions
diff --git a/libs/surfaces/websockets/client.h b/libs/surfaces/websockets/client.h
index 1f75163338..bf90fb5ad0 100644
--- a/libs/surfaces/websockets/client.h
+++ b/libs/surfaces/websockets/client.h
@@ -19,7 +19,7 @@
#ifndef client_context_h
#define client_context_h
-#include <unordered_set>
+#include <boost/unordered_set.hpp>
#include <list>
#include "state.h"
@@ -48,7 +48,7 @@ class ClientContext
Client _wsi;
- typedef std::unordered_set<NodeState> ClientState;
+ typedef boost::unordered_set<NodeState> ClientState;
ClientState _state;
ClientOutputBuffer _output_buf;
diff --git a/libs/surfaces/websockets/dispatcher.cc b/libs/surfaces/websockets/dispatcher.cc
index dbb627a027..88cd2024e4 100644
--- a/libs/surfaces/websockets/dispatcher.cc
+++ b/libs/surfaces/websockets/dispatcher.cc
@@ -187,8 +187,8 @@ WebsocketsDispatcher::strip_plugin_param_value_handler (Client client, const Nod
}
void
-WebsocketsDispatcher::update (Client client, std::string node,
- std::initializer_list<uint32_t> addr, std::initializer_list<TypedValue> val)
+WebsocketsDispatcher::update (Client client, std::string node, std::vector<uint32_t> addr,
+ std::vector<TypedValue> val)
{
server ().update_client (client, { node, addr, val }, true);
}
diff --git a/libs/surfaces/websockets/dispatcher.h b/libs/surfaces/websockets/dispatcher.h
index 07739ee218..a6b60d9221 100644
--- a/libs/surfaces/websockets/dispatcher.h
+++ b/libs/surfaces/websockets/dispatcher.h
@@ -19,7 +19,7 @@
#ifndef websockets_dispatcher_h
#define websockets_dispatcher_h
-#include <unordered_map>
+#include <boost/unordered_map.hpp>
#include "component.h"
#include "client.h"
@@ -39,7 +39,7 @@ class WebsocketsDispatcher : public SurfaceComponent
private:
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;
@@ -50,8 +50,7 @@ class WebsocketsDispatcher : public SurfaceComponent
void strip_plugin_enable_handler (Client, const NodeStateMessage&);
void strip_plugin_param_value_handler (Client, const NodeStateMessage&);
- void update (Client, std::string, std::initializer_list<uint32_t>,
- std::initializer_list<TypedValue>);
+ void update (Client, std::string, std::vector<uint32_t>, std::vector<TypedValue>);
};
diff --git a/libs/surfaces/websockets/feedback.cc b/libs/surfaces/websockets/feedback.cc
index 7cb52a76ef..de7fad9c7e 100644
--- a/libs/surfaces/websockets/feedback.cc
+++ b/libs/surfaces/websockets/feedback.cc
@@ -164,8 +164,7 @@ ArdourFeedback::observe_strip_plugin_param_values (uint32_t strip_n,
}
void
-ArdourFeedback::update_all (std::string node, std::initializer_list<uint32_t> addr,
- TypedValue val) const
+ArdourFeedback::update_all (std::string node, std::vector<uint32_t> addr, TypedValue val) const
{
server ().update_all_clients ({ node, addr, { val }}, false);
}
diff --git a/libs/surfaces/websockets/feedback.h b/libs/surfaces/websockets/feedback.h
index 8a8c6d33d4..c4490ca09e 100644
--- a/libs/surfaces/websockets/feedback.h
+++ b/libs/surfaces/websockets/feedback.h
@@ -49,7 +49,7 @@ class ArdourFeedback : public SurfaceComponent
void observe_strip_plugin_param_values (uint32_t, uint32_t,
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;
};
diff --git a/libs/surfaces/websockets/message.cc b/libs/surfaces/websockets/message.cc
index 941e01f539..b82291d245 100644
--- a/libs/surfaces/websockets/message.cc
+++ b/libs/surfaces/websockets/message.cc
@@ -47,13 +47,13 @@ NodeStateMessage::NodeStateMessage (void *buf, size_t len)
, _write (false)
{
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::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 ());
diff --git a/libs/surfaces/websockets/server.cc b/libs/surfaces/websockets/server.cc
index e3f8fe7b7e..178aeca011 100644
--- a/libs/surfaces/websockets/server.cc
+++ b/libs/surfaces/websockets/server.cc
@@ -25,8 +25,7 @@
using namespace Glib;
-WebsocketsServer::WebsocketsServer
- (ArdourSurface::ArdourWebsockets& surface)
+WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface)
: SurfaceComponent (surface)
, _lws_context (0)
{
diff --git a/libs/surfaces/websockets/server.h b/libs/surfaces/websockets/server.h
index afb136f442..462b4887f3 100644
--- a/libs/surfaces/websockets/server.h
+++ b/libs/surfaces/websockets/server.h
@@ -19,7 +19,7 @@
#ifndef websockets_server_h
#define websockets_server_h
-#include <unordered_map>
+#include <boost/unordered_map.hpp>
#include <libwebsockets.h>
#if LWS_LIBRARY_VERSION_MAJOR < 3
@@ -68,10 +68,10 @@ class WebsocketsServer : public SurfaceComponent
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;
- typedef std::unordered_map<Client, ClientContext> ClientContextMap;
+ typedef boost::unordered_map<Client, ClientContext> ClientContextMap;
ClientContextMap _client_ctx;
void add_poll_fd (struct lws_pollargs*);
diff --git a/libs/surfaces/websockets/state.cc b/libs/surfaces/websockets/state.cc
index ed31103863..63e76b4afb 100644
--- a/libs/surfaces/websockets/state.cc
+++ b/libs/surfaces/websockets/state.cc
@@ -17,28 +17,20 @@
*/
#include <sstream>
+#include <boost/unordered_set.hpp>
#include "state.h"
-NodeState::NodeState ()
-{
- update_node_addr_hash ();
-}
+NodeState::NodeState () { }
NodeState::NodeState (std::string node)
- : _node (node)
-{
- update_node_addr_hash ();
-}
+ : _node (node) { }
-NodeState::NodeState (std::string node, std::initializer_list<uint32_t> addr,
- std::initializer_list<TypedValue> val)
+NodeState::NodeState (std::string node, std::vector<uint32_t> addr,
+ std::vector<TypedValue> val)
: _node (node)
, _addr (addr)
- , _val (val)
-{
- update_node_addr_hash ();
-}
+ , _val (val) { }
std::string
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) {
s << std::endl << " val " << it->debug_str ();
}
-
- s << std::endl << " hash = " << _node_addr_hash;
return s.str ();
}
@@ -79,7 +69,6 @@ void
NodeState::add_addr (uint32_t addr)
{
_addr.push_back (addr);
- update_node_addr_hash ();
}
int
@@ -104,15 +93,22 @@ NodeState::add_val (TypedValue val)
_val.push_back (val);
}
-void
-NodeState::update_node_addr_hash ()
+std::size_t
+NodeState::node_addr_hash () const
{
- std::stringstream ss;
- ss << _node;
+ std::size_t seed = 0;
+ boost::hash_combine (seed, _node);
+ boost::hash_combine (seed, _addr);
+ return seed;
+}
- for (std::vector<uint32_t>::iterator it = _addr.begin (); it != _addr.end (); ++it) {
- ss << "_" << *it;
- }
+bool
+NodeState::operator== (const NodeState& other) const
+{
+ return node_addr_hash () == other.node_addr_hash ();
+}
- _node_addr_hash = ss.str ();
+std::size_t hash_value (const NodeState &state)
+{
+ return state.node_addr_hash ();
}
diff --git a/libs/surfaces/websockets/state.h b/libs/surfaces/websockets/state.h
index 814eb3ccd4..f9e0f8d19e 100644
--- a/libs/surfaces/websockets/state.h
+++ b/libs/surfaces/websockets/state.h
@@ -19,9 +19,10 @@
#ifndef node_state_h
#define node_state_h
-#include <vector>
+#include <stdint.h>
#include <cmath>
#include <cstring>
+#include <vector>
#include "typed_value.h"
@@ -36,7 +37,7 @@ namespace Node {
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_value = "strip_plugin_param_value";
-};
+}
class NodeState {
@@ -44,8 +45,8 @@ class NodeState {
NodeState ();
NodeState (std::string);
- NodeState (std::string, std::initializer_list<uint32_t>,
- std::initializer_list<TypedValue> = {});
+ NodeState (std::string, std::vector<uint32_t>,
+ std::vector<TypedValue> = std::vector<TypedValue>());
std::string debug_str () const;
@@ -59,37 +60,18 @@ class NodeState {
TypedValue nth_val (int) const;
void add_val (TypedValue);
+ std::size_t node_addr_hash () const;
+
+ bool operator== (const NodeState& other) const;
+
private:
std::string _node;
std::vector<uint32_t> _addr;
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 {
- 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;
- }
- };
-}
+std::size_t hash_value (const NodeState&);
#endif // node_state_h
diff --git a/libs/surfaces/websockets/strips.h b/libs/surfaces/websockets/strips.h
index fd740c1bad..264ce85eb2 100644
--- a/libs/surfaces/websockets/strips.h
+++ b/libs/surfaces/websockets/strips.h
@@ -62,7 +62,7 @@ class ArdourStrips : public SurfaceComponent
private:
- typedef std::vector<boost::shared_ptr<ARDOUR::Stripable>> StripableVector;
+ typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > StripableVector;
StripableVector _strips;
};
diff --git a/libs/surfaces/websockets/typed_value.cc b/libs/surfaces/websockets/typed_value.cc
index 808142a36f..3c44c66d4e 100644
--- a/libs/surfaces/websockets/typed_value.cc
+++ b/libs/surfaces/websockets/typed_value.cc
@@ -19,11 +19,43 @@
#include <cmath>
#include <limits>
#include <string>
+#include <boost/lexical_cast.hpp>
#include "typed_value.h"
#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
bool () const
{
@@ -53,8 +85,8 @@ int () const
return static_cast<int>(_d);
case String:
try {
- return std::stoi (_s);
- } catch (const std::exception&) {
+ return boost::lexical_cast<int> (_s);
+ } catch (const boost::bad_lexical_cast&) {
return 0;
}
default:
@@ -74,8 +106,8 @@ double () const
return static_cast<double>(_i);
case String:
try {
- return std::stod (_s);
- } catch (const std::exception&) {
+ return boost::lexical_cast<double> (_s);
+ } catch (const boost::bad_lexical_cast&) {
return 0;
}
default:
@@ -92,9 +124,9 @@ std::string () const
case Bool:
return _b ? "true" : "false";
case Int:
- return std::to_string (_i);
+ return boost::lexical_cast<std::string> (_i);
case Double:
- return std::to_string (_d);
+ return boost::lexical_cast<std::string> (_d);
default:
return "";
}
diff --git a/libs/surfaces/websockets/typed_value.h b/libs/surfaces/websockets/typed_value.h
index 0f4680d693..a30ef3e940 100644
--- a/libs/surfaces/websockets/typed_value.h
+++ b/libs/surfaces/websockets/typed_value.h
@@ -33,11 +33,11 @@ class TypedValue
String
};
- TypedValue (): _type (Empty) { }
- TypedValue (bool value): _type { Bool }, _b (value) { }
- TypedValue (int value): _type { Int }, _i (value) { }
- TypedValue (double value): _type { Double }, _d (value) { }
- TypedValue (std::string value): _type { String }, _s (value) { }
+ TypedValue ();
+ TypedValue (bool);
+ TypedValue (int);
+ TypedValue (double);
+ TypedValue (std::string);
bool empty () const { return _type == Empty; };
Type type () const { return _type; };
@@ -55,9 +55,9 @@ class TypedValue
private:
Type _type;
- bool _b = false;
- int _i = 0;
- double _d = 0.0;
+ bool _b;
+ int _i;
+ double _d;
std::string _s;
};