From bb96ebfc14c674fa9bf43c7667939530eb703e71 Mon Sep 17 00:00:00 2001 From: Robert Ramey Date: Fri, 3 Jul 2015 22:40:22 -0700 Subject: [PATCH] Moved policies implementation to development --- CMake/CTestConfig.cmake | 11 ++++ doc/html/safe_cast.html | 117 --------------------------------- doc/html/safe_compare.html | 130 ------------------------------------- include/overflow.hpp | 32 +++++++++ 4 files changed, 43 insertions(+), 247 deletions(-) create mode 100644 CMake/CTestConfig.cmake delete mode 100644 doc/html/safe_cast.html delete mode 100644 doc/html/safe_compare.html create mode 100644 include/overflow.hpp diff --git a/CMake/CTestConfig.cmake b/CMake/CTestConfig.cmake new file mode 100644 index 0000000..a0b5924 --- /dev/null +++ b/CMake/CTestConfig.cmake @@ -0,0 +1,11 @@ +## This file should be placed in the root directory of your project. +## Then modify the CMakeLists.txt file in the root directory of your +## project to incorporate the testing dashboard. +## # The following are required to uses Dart and the Cdash dashboard +set(CTEST_PROJECT_NAME "Safe Numerics") +set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "my.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=Safe+Numerics") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/doc/html/safe_cast.html b/doc/html/safe_cast.html deleted file mode 100644 index ac908c1..0000000 --- a/doc/html/safe_cast.html +++ /dev/null @@ -1,117 +0,0 @@ - - - -safe_cast<T, U> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-safe_cast<T, U>

- -
-

-Synopsis

-
template<class T, class U>
-T safe_cast(const U & u);
-
-
-

-Description

-

Converts one Numeric - type to another. Throws an std::out_of_range exception if - such a conversion is not possible without changing the value. This - function is part of the implementation of the safe numerics library. It's - been made publicly because it might be useful in related contexts.

-
-
-

-Type requirements

-
---- - - - - - - - - - - - - - - -
TypeRequirements
TNumeric
U Numeric
-
-
-

-Preconditions

-

The value of u must be representable by the type T. If - this is not true, an std::out_of_range exception will be - thrown.

-
- -
-

-Example of use

-
#include <boost/numeric/safe_cast.hpp> 
-#include <boost/numeric/safe_integer.hpp> 
-
-void f(){
-    safe_integer<char> i;
-    unsigned char j;
-    i = 1;
-    j = safe_cast<unsigned char>(i);  // ok
-    i = -1;
-    j = safe_cast<unsigned char>(i);  // throws std::out_of_range exception
-    i = 1024;
-    j = safe_cast<unsigned char>(i);  // throws std::out_of_range exception
-}
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/safe_compare.html b/doc/html/safe_compare.html deleted file mode 100644 index 0842dce..0000000 --- a/doc/html/safe_compare.html +++ /dev/null @@ -1,130 +0,0 @@ - - - -safe_compare<T, U> - - - - - - - - - - - - - - - -
pre-boostHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-safe_compare<T, U>

- -
-

-Synopsis

-

safe_compare is several functions:.

-
template<class T, class U>
-bool safe_compare::less_than(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::less_than_equal(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::greater_than(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::greater_than_equal(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::equal(const T & lhs, const U & rhs);
-
-template<class T, class U>
-bool safe_compare::not_equal(const T & lhs, const U & rhs);
-
-
-

-Description

-

With normal comparison operators, comparison of unsigned types to - signed types will be done by converting the unsigned type to a signed type - before comparing. Unfortunately this is not always possible. Most C++ - compilers will emit an warning message when this is possible but won't - check that an error is made in the conversion. This function guarantees a - correct result regardless of the types of the arguments. It's used in the - implementation of the safe numerics library. It has been made publicly - accessible in because it might be useful in other contexts.

-
-
-

-Type requirements

-
---- - - - - - - - - - - - - - - -
TypeRequirements
TNumeric
U Numeric
-
- -
-

-Example of use

-
#include <boost/numeric/safe_compare.hpp>
-
-void f(){
-    unsigned char i = 129;
-    unsigned int j = 1;
-    assert(j < i); // program traps because expression is false. But this is a surprise because 1 < 129
-    assert( safe_compare::less_than(j,i)); // expression is true as we would expect
-}
-
-// safe_compare is used to implement comparison operators for safe types.  So we can do this:
-void g(){
-    safe<unsigned char> int i = 0x129;
-    safe<int> j = 1;
-    assert(j < i); // program works as expected
-}
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/include/overflow.hpp b/include/overflow.hpp new file mode 100644 index 0000000..d39035d --- /dev/null +++ b/include/overflow.hpp @@ -0,0 +1,32 @@ +#ifndef BOOST_NUMERIC_SAFE_OVERFLOW_HPP +#define BOOST_NUMERIC_SAFE_OVERFLOW_HPP + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +// Copyright (c) 2012 Robert Ramey +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +namespace boost { +namespace numeric { + +#ifndef BOOST_NO_EXCEPTIONS + inline void overflow(char const * const msg) { + throw std::range_error(msg); + } +#else + void overflow(char const * const msg); +#endif + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_SAFE_OVERFLOW_HPP