DUDS
Distributed Update of Data from Something
DigitalPinSet.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
11 
12 namespace duds { namespace hardware { namespace interface {
13 
15  const std::shared_ptr<DigitalPort> &port,
16  const std::vector<unsigned int> &pvec
17 ) : DigitalPinBase(port), pinvec(pvec) {
18  // no port?
19  if (!port) {
21  }
22  // check for pin non-existence
23  std::vector<unsigned int>::const_iterator iter = pinvec.cbegin();
24  for (; iter != pinvec.cend(); ++iter) {
25  if ((*iter != -1) && !port->exists(*iter)) {
26  // bad pin
28  PinErrorId(*iter) << DigitalPortAffected(port.get())
29  );
30  }
31  }
32 }
33 
35  const std::shared_ptr<DigitalPort> &port,
36  std::vector<unsigned int> &&pvec
37 ) : DigitalPinBase(port), pinvec(std::move(pvec)) {
38  try {
39  // no port?
40  if (!port) {
42  }
43  // check for pin non-existence
44  std::vector<unsigned int>::const_iterator iter = pinvec.cbegin();
45  for (; iter != pinvec.cend(); ++iter) {
46  if ((*iter != -1) && !port->exists(*iter)) {
47  // bad pin
49  PinErrorId(*iter) << DigitalPortAffected(port.get())
50  );
51  }
52  }
53  } catch (...) {
54  // restore the provided vector
55  pvec = std::move(pinvec);
56  throw;
57  }
58 }
59 
60 } } } // namespaces
A required DigitalPort object was not supplied.
STL namespace.
std::vector< unsigned int > pinvec
The port global pin IDs this object will represent.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
const std::shared_ptr< DigitalPort > & port() const
Returns the port that grants access to the pin(s) referenced by this object.
A pin required for the operation does not exist or is unavailable to the process. ...
Definition: PinErrors.hpp:70
DigitalPinSet()=default
Constructs DigitalPinSet object with nothing to represent.
boost::error_info< struct Info_PinId, unsigned int > PinErrorId
The pin global ID involved in the error.
Definition: PinErrors.hpp:97
boost::error_info< struct Info_DigitalPortAffected, const DigitalPort * > DigitalPortAffected
Added to exceptions thrown by DigitalPort objects.
A base class for classes that represent one or more pins on a single DigitalPort, but do not provide ...
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Definition: Errors.hpp:48