13
0
livetrax/libs/surfaces/websockets/state.cc

130 lines
2.4 KiB
C++
Raw Normal View History

2020-02-20 07:12:36 -05:00
/*
* Copyright (C) 2020 Luciano Iam <oss@lucianoiam.com>
2020-02-20 07:12:36 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <boost/functional/hash.hpp>
#include <sstream>
2020-02-20 07:12:36 -05:00
#include "state.h"
using namespace ArdourSurface;
NodeState::NodeState () {}
2020-02-20 07:12:36 -05:00
NodeState::NodeState (std::string node)
: _node (node)
{
}
2020-02-20 07:12:36 -05:00
2020-02-22 06:38:49 -05:00
NodeState::NodeState (std::string node, AddressVector addr, ValueVector val)
2020-02-20 07:12:36 -05:00
: _node (node)
, _addr (addr)
, _val (val)
{
}
2020-02-20 07:12:36 -05:00
std::string
2020-02-20 07:12:36 -05:00
NodeState::debug_str () const
{
std::stringstream s;
s << "node = " << _node;
if (!_addr.empty ()) {
s << std::endl
<< " addr = ";
for (AddressVector::const_iterator it = _addr.begin (); it != _addr.end (); ++it) {
s << *it << ";";
}
}
for (ValueVector::const_iterator it = _val.begin (); it != _val.end (); ++it) {
s << std::endl
<< " val " << it->debug_str ();
}
return s.str ();
2020-02-20 07:12:36 -05:00
}
int
NodeState::n_addr () const
{
return static_cast<int> (_addr.size ());
2020-02-20 07:12:36 -05:00
}
uint32_t
NodeState::nth_addr (int n) const
{
return _addr[n];
2020-02-20 07:12:36 -05:00
}
void
NodeState::add_addr (uint32_t addr)
{
_addr.push_back (addr);
2020-02-20 07:12:36 -05:00
}
int
NodeState::n_val () const
{
return static_cast<int> (_val.size ());
2020-02-20 07:12:36 -05:00
}
TypedValue
NodeState::nth_val (int n) const
{
if (n_val () < n) {
return TypedValue ();
}
2020-02-20 07:12:36 -05:00
return _val[n];
2020-02-20 07:12:36 -05:00
}
void
NodeState::add_val (TypedValue val)
{
_val.push_back (val);
2020-02-20 07:12:36 -05:00
}
2020-02-20 17:16:02 -05:00
std::size_t
NodeState::node_addr_hash () const
2020-02-20 07:12:36 -05:00
{
std::size_t seed = 0;
boost::hash_combine (seed, _node);
boost::hash_combine (seed, _addr);
return seed;
2020-02-20 17:16:02 -05:00
}
2020-02-20 07:12:36 -05:00
2020-02-20 17:16:02 -05:00
bool
NodeState::operator== (const NodeState& other) const
{
return node_addr_hash () == other.node_addr_hash ();
2020-02-20 17:16:02 -05:00
}
2020-02-20 07:12:36 -05:00
bool
NodeState::operator< (const NodeState& other) const
{
return node_addr_hash () < other.node_addr_hash ();
}
std::size_t
hash_value (const NodeState& state)
2020-02-20 17:16:02 -05:00
{
return state.node_addr_hash ();
2020-02-20 07:12:36 -05:00
}