Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #44 from forno/dy/reformat/allcode
Browse files Browse the repository at this point in the history
Reformat all codes
  • Loading branch information
forno authored Jan 27, 2017
2 parents 36df2c2 + 54137aa commit bf3590b
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 27 deletions.
2 changes: 2 additions & 0 deletions include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Core
using Container = std::vector<value_type>;
using IDContainerTx = std::array<value_type, 4>;
using IDContainerRx = std::array<value_type, 5>;

explicit Core(const std::string&, speed_t); // touch by only libics3
~Core() noexcept;
Core(const Core&) = delete;
Expand All @@ -51,6 +52,7 @@ class Core
Core& operator=(Core&&) noexcept;

static std::unique_ptr<Core> getCore(const std::string&, speed_t);

void communicate(const Container&, Container&);
void communicateID(const IDContainerTx&, IDContainerRx&);
private:
Expand Down
8 changes: 6 additions & 2 deletions include/ics3/angle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace ics
{
class ICS3;

class Angle
{
friend ICS3; // for touch rawData
public:
using rawType = uint16_t;
using type = double;

static constexpr Angle newDegree(type = 0.0);
static constexpr Angle newRadian(type = 0.0);
static constexpr Angle newSameUnit(const Angle&, type = 0.0);
Expand All @@ -49,6 +51,7 @@ class Angle

Angle(const Angle&) noexcept = default;
Angle& operator=(const Angle&) noexcept;

constexpr type get() const noexcept;
constexpr operator type() const noexcept;
void set(type);
Expand All @@ -57,6 +60,7 @@ class Angle
void setRaw(rawType);
private:
constexpr Angle(type, type); // non explicit, user cannot touch this

static constexpr rawType castToRaw(type, type) noexcept;
static constexpr rawType checkValidAngle(rawType);

Expand Down Expand Up @@ -122,8 +126,8 @@ inline void Angle::setRaw(rawType raw)
}

constexpr Angle::Angle(type calibration, type angle)
: rawData {checkValidAngle(castToRaw(calibration, angle))}, // throw std::out_of_range
rawCalibration {calibration}
: rawData {checkValidAngle(castToRaw(calibration, angle))}, // throw std::out_of_range
rawCalibration {calibration}
{
}

Expand Down
6 changes: 4 additions & 2 deletions include/ics3/baudrate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class Baudrate
{
public:
using type = uint8_t;

static constexpr Baudrate RATE115200() noexcept;
//static constexpr Baudrate RATE625000() noexcept;
//static constexpr Baudrate RATE1250000() noexcept;

constexpr type get() const noexcept;
constexpr operator type() const noexcept;
constexpr speed_t getSpeed() const noexcept;
Expand Down Expand Up @@ -69,8 +71,8 @@ constexpr speed_t Baudrate::getSpeed() const noexcept
}

constexpr Baudrate::Baudrate(type romdata, speed_t baudrate) noexcept
: romdata {romdata},
baudrate {baudrate}
: romdata {romdata},
baudrate {baudrate}
{
}
}
Expand Down
26 changes: 14 additions & 12 deletions include/ics3/eepparam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class EepParam
using TargetContainer = std::array<uint8_t, 64>;
using size_type = TargetContainer::size_type;
using ValidChecker = type (&)(type, type, type);

enum Flag : type
{
REVERSE = 0x01,
Expand Down Expand Up @@ -86,6 +87,7 @@ class EepParam
type,
ValidChecker,
type);

static constexpr type checkValidRange(type, type, type);
static constexpr type checkValidEvenRange(type, type, type);
static constexpr type checkValidFlag(type, type, type);
Expand Down Expand Up @@ -237,18 +239,18 @@ inline void EepParam::write(TargetContainer& dest) const noexcept
}

constexpr EepParam::EepParam(
size_type offset,
size_type length,
type min,
type max,
ValidChecker setFunc,
type data)
: offset(offset),
length(length),
min(min),
max(max),
setFunc(setFunc),
data(setFunc(data, min, max)) // throw std::invalid_argument, std::out_of_range
size_type offset,
size_type length,
type min,
type max,
ValidChecker setFunc,
type data)
: offset(offset),
length(length),
min(min),
max(max),
setFunc(setFunc),
data(setFunc(data, min, max)) // throw std::invalid_argument, std::out_of_range
{
}

Expand Down
2 changes: 1 addition & 1 deletion include/ics3/eeprom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ inline void EepRom::write(Iter&& dest) const
}

inline EepRom::EepRom(const Container& src)
: data(src) // for Ubuntu14.04 compiler
: data(src) // for Ubuntu14.04 compiler
{
}
}
Expand Down
1 change: 1 addition & 0 deletions include/ics3/ics3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ICS3
public:
explicit ICS3(const std::string&, const Baudrate& = Baudrate::RATE115200());
~ICS3() noexcept;

Angle move(const ID&, Angle);
Angle free(const ID&, Angle = Angle::newRadian());
Parameter get(const ID&, const Parameter&);
Expand Down
4 changes: 3 additions & 1 deletion include/ics3/id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ class ID
{
public:
using type = uint8_t;

constexpr ID(type); // ID is non explicit constructor because only do check limit

constexpr type get() const noexcept;
constexpr operator type() const noexcept;
private:
const type data;
};

constexpr ID::ID(type id)
: data {id < 32 ? id : throw std::invalid_argument {"invalid ID: must be 0 <= id <= 31"}}
: data {id < 32 ? id : throw std::invalid_argument {"invalid ID: must be 0 <= id <= 31"}}
{
}

Expand Down
9 changes: 5 additions & 4 deletions include/ics3/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Parameter
{
public:
using type = uint8_t;

static constexpr Parameter stretch(type = 30);
static constexpr Parameter speed(type = 127);
static constexpr Parameter current(type = 63);
Expand Down Expand Up @@ -107,10 +108,10 @@ constexpr Parameter::type Parameter::getSubcommand() const noexcept
}

constexpr Parameter::Parameter(type sc, type min, type max, type defaultData)
: sc {sc},
min {min},
max {max},
data {checkValidRange(defaultData, min, max)}
: sc {sc},
min {min},
max {max},
data {checkValidRange(defaultData, min, max)}
{
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ inline std::unique_ptr<T> make_unique(Args&&... args)
}

ics::Core::Core(const std::string& path, speed_t baudrate)
: fd {open(path.c_str(), O_RDWR | O_NOCTTY)},
oldTio {}
: fd {open(path.c_str(), O_RDWR | O_NOCTTY)},
oldTio {}
{
if (fd < 0)
throw std::runtime_error {"Cannot open deveice"};
Expand Down Expand Up @@ -70,8 +70,8 @@ ics::Core::~Core() noexcept
}

ics::Core::Core(Core&& rhs) noexcept
: fd {rhs.fd},
oldTio(rhs.oldTio) // for Ubuntu14.04 compiler
: fd {rhs.fd},
oldTio(rhs.oldTio) // for Ubuntu14.04 compiler
{
rhs.fd = -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ics3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static inline ics::Core::value_type getCmd(const ics::Core::value_type head, con
}

ics::ICS3::ICS3(const std::string& path, const Baudrate& baudrate)
: core {Core::getCore(path, baudrate.getSpeed())} // throw std::invalid_argument, std::runtime_error
: core {Core::getCore(path, baudrate.getSpeed())} // throw std::invalid_argument, std::runtime_error
{
}

Expand Down

0 comments on commit bf3590b

Please sign in to comment.