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
#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;

View File

@ -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);
}

View File

@ -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>);
};

View File

@ -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);
}

View File

@ -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;
};

View File

@ -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 ());

View File

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

View File

@ -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*);

View File

@ -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;
for (std::vector<uint32_t>::iterator it = _addr.begin (); it != _addr.end (); ++it) {
ss << "_" << *it;
}
_node_addr_hash = ss.str ();
std::size_t seed = 0;
boost::hash_combine (seed, _node);
boost::hash_combine (seed, _addr);
return seed;
}
bool
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
#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

View File

@ -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;
};

View File

@ -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 "";
}

View File

@ -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;
};