OSDN Git Service

Wrote some texts, fixed configure.in and Makefile.am, and fixed islibfunc.hpp, system...
[islib/islib.git] / islibfunc.hpp
1 #ifndef DEFINES_ISLIB_ISLIBFUNC_HPP
2
3 #define DEFINES_ISLIB_ISLIBFUNC_HPP
4
5 //
6 // Inclusion of standard header file
7 //
8 #include <cassert>
9 #include <cstddef>
10 #include <ctime>
11 #include <iostream>
12 #include <stdexcept>
13 #include <string>
14 #include <utility>
15
16 //
17 // Inclusion of system header file
18 //
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #include <signal.h>
22 #include <utime.h>
23
24 //
25 // Inclusion of library header file
26 //
27 #include <boost/filesystem/path.hpp>
28
29 namespace islib
30   {
31     //
32     // Declaration of function
33     //
34     void link_ ( boost::filesystem::path const &, boost::filesystem::path const & );
35     void localtime_r_ ( std::time_t const *, struct std::tm * );
36     void mkdir_ ( boost::filesystem::path const &, mode_t );
37     void raise_ ( int );
38     void raise_fatal ( int );
39     void sigaction_ ( int, struct sigaction const *, struct sigaction * );
40     void sigaction_fatal ( int, struct sigaction const *, struct sigaction * );
41     void sigfillset_ ( sigset_t * );
42     void sigfillset_fatal ( sigset_t * );
43     void sigprocmask_ ( int, sigset_t const *, sigset_t * );
44     void sigprocmask_fatal ( int, sigset_t const *, sigset_t * );
45     std::time_t time ();
46     void stat_ ( boost::filesystem::path const &, struct stat * );
47     void unlink_ ( boost::filesystem::path const & );
48     void utime_ ( boost::filesystem::path const &, struct utimbuf const * );
49     void write_ ( int, void const *, std::size_t );
50     void write_assert ( int, void const *, std::size_t );
51
52     //
53     // Declaration of template function
54     //
55     template < typename Value_Type, typename Permissible_Error_Type > bool equals_to ( Value_Type const &, Value_Type const &, Permissible_Error_Type const & );
56     template < typename Value_Type, typename Permissible_Error_Type > bool does_not_equal_to ( Value_Type const &, Value_Type const &, Permissible_Error_Type const & );
57     template < typename Value_Type, typename Permissible_Error_Type > bool is_less_than ( Value_Type const &, Value_Type const &, Permissible_Error_Type const & );
58     template < typename Value_Type, typename Permissible_Error_Type > bool is_greater_than ( Value_Type const &, Value_Type const &, Permissible_Error_Type const & );
59     template < typename Value_Type, typename Permissible_Error_Type > bool is_less_than_or_equals_to ( Value_Type const &, Value_Type const &, Permissible_Error_Type const & );
60     template < typename Value_Type, typename Permissible_Error_Type > bool is_greater_than_or_equals_to ( Value_Type const &, Value_Type const &, Permissible_Error_Type const & );
61
62     //
63     // Definition of inline function
64     //
65     inline
66     void
67     assert_
68       (
69         bool const expression,
70         std::string const &cause
71       )
72       {
73
74 #ifndef NDEBUG
75
76         if ( !expression )
77           std::cerr << cause << std::endl;
78
79 #endif // NDEBUG
80
81         assert ( expression );
82       }
83
84     //
85     // Definition of template function
86     //
87     template
88       <
89         typename Exception_Type
90       >
91     void
92     throw_
93       (
94         Exception_Type const &exception
95       )
96       {
97
98 #ifndef DO_NOT_USE_THROW_
99
100         throw exception;
101
102 #else // DO_NOT_USE_THROW_
103
104         assert_ ( false, exception.what () );
105
106 #endif // DO_NOT_USE_THROW_
107
108       }
109
110     //
111     // Definition of template function
112     //
113     template
114       <
115         typename Exception_Type
116       >
117     void
118     throw_if
119       (
120         Exception_Type const &exception,
121         bool const predicate
122       )
123       {
124
125 #ifndef DO_NOT_USE_THROW_IF
126
127         if ( predicate )
128           throw exception;
129
130 #else // DO_NOT_USE_THROW_IF
131         
132         if ( predicate )
133           assert_ ( false, exception.what () );
134
135 #endif // DO_NOT_USE_THROW_IF
136
137       }
138
139     //
140     // Definition of template function
141     //
142     template
143       <
144         typename Container_Type,
145         typename Value_Type
146       >
147     void
148     insert
149       (
150         Container_Type &container,
151         Value_Type const &value
152       )
153       {
154         std::pair < typename Container_Type::iterator, bool > const insert_return_value = container.insert ( value );
155
156         throw_if ( std::logic_error ( "islib::insert: !insert_return_value.second" ), !insert_return_value.second );
157       }
158   }
159
160 #endif // DEFINES_ISLIB_ISLIBFUNC_HPP
161
162 //
163 // End of file
164 //