]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/safe_numerics/example/example91.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / safe_numerics / example / example91.cpp
CommitLineData
92f5a8d4
TL
1//////////////////////////////////////////////////////////////////
2// example91.cpp
3//
4// Copyright (c) 2015 Robert Ramey
5//
6// Distributed under the Boost Software License, Version 1.0. (See
7// accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10#include <iostream>
11#include <limits>
12
13#include <boost/safe_numerics/cpp.hpp>
14#include <boost/safe_numerics/safe_integer.hpp>
15#include <boost/safe_numerics//safe_integer_range.hpp>
16
17// use same type promotion as used by the pic compiler
18// see the following comment in motor.c
19// Types: int8,int16,int32=8,16,32bit integers
20
21using pic16_promotion = boost::safe_numerics::cpp<
22 8, // char
23 8, // short
24 8, // int
25 16, // long
26 32 // long long
27>;
28
29// define safe types used desktop version of the program. In conjunction
30// with the promotion policy above, this will permit us to guarantee that
31// the resulting program will be free of arithmetic errors introduced by
32// C expression syntax and type promotion with no runtime penalty
33template <typename T> // T is char, int, etc data type
34using safe_t = boost::safe_numerics::safe<
35 T,
36 pic16_promotion,
37 boost::safe_numerics::default_exception_policy // use for compiling and running tests
38>;
39using safe_bool_t = boost::safe_numerics::safe_unsigned_range<
40 0,
41 1,
42 pic16_promotion,
43 boost::safe_numerics::default_exception_policy // use for compiling and running tests
44>;
45
46#define DESKTOP
47#include "motor1.c"
48
49#include <chrono>
50#include <thread>
51
52void sleep(int16){
53 std::this_thread::sleep_for(std::chrono::microseconds(ccpr));
54}
55
56int main(){
57 std::cout << "start test\n";
58 try{
59 initialize();
60 motor_run(100);
61 do{
62 isr_motor_step();
63 }while (run_flg);
64
65 // move motor to position 1000
66 motor_run(1000);
67 do{
68 sleep(ccpr);
69 isr_motor_step();
70 }while (run_flg);
71
72 // move back to position 0
73 motor_run(0);
74 do{
75 sleep(ccpr);
76 isr_motor_step();
77 }while (run_flg);
78 }
79 catch(std::exception & e){
80 std::cout << e.what() << '\n';
81 // we expect to trap an exception
82 return 0;
83 }
84 catch(...){
85 std::cout << "test interrupted\n";
86 return 1;
87 }
88 std::cout << "end test\n";
89 return 1;
90}