2020-02-20 07:12:36 -05:00
|
|
|
/*
|
2021-06-13 10:32:18 -04: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.
|
|
|
|
*/
|
|
|
|
|
2020-02-20 17:16:02 -05:00
|
|
|
#include <boost/unordered_set.hpp>
|
2020-02-23 10:03:59 -05:00
|
|
|
#include <sstream>
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
#include "state.h"
|
|
|
|
|
2020-08-30 15:15:07 -04:00
|
|
|
using namespace ArdourSurface;
|
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
NodeState::NodeState () {}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
NodeState::NodeState (std::string node)
|
2020-02-23 10:03:59 -05:00
|
|
|
: _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)
|
2020-02-23 10:03:59 -05:00
|
|
|
, _val (val)
|
|
|
|
{
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
std::string
|
2020-02-20 07:12:36 -05:00
|
|
|
NodeState::debug_str () const
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
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
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return static_cast<int> (_addr.size ());
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
NodeState::nth_addr (int n) const
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return _addr[n];
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NodeState::add_addr (uint32_t addr)
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
_addr.push_back (addr);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
NodeState::n_val () const
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return static_cast<int> (_val.size ());
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TypedValue
|
|
|
|
NodeState::nth_val (int n) const
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
if (n_val () < n) {
|
|
|
|
return TypedValue ();
|
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
return _val[n];
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NodeState::add_val (TypedValue val)
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
_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
|
|
|
{
|
2020-02-23 10:03:59 -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
|
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return node_addr_hash () == other.node_addr_hash ();
|
2020-02-20 17:16:02 -05:00
|
|
|
}
|
2020-02-20 07:12:36 -05:00
|
|
|
|
2020-08-31 02:28:13 -04:00
|
|
|
bool
|
|
|
|
NodeState::operator< (const NodeState& other) const
|
|
|
|
{
|
|
|
|
return node_addr_hash () < other.node_addr_hash ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-23 10:03:59 -05:00
|
|
|
std::size_t
|
|
|
|
hash_value (const NodeState& state)
|
2020-02-20 17:16:02 -05:00
|
|
|
{
|
2020-02-23 10:03:59 -05:00
|
|
|
return state.node_addr_hash ();
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|