mist_conf.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 
33 
34 #ifndef __INCLUDE_MIST_CONF_H__
35 #define __INCLUDE_MIST_CONF_H__
36 
37 #include <iostream>
38 #include <cstdlib>
39 #include <cstddef>
40 #include <string>
41 
42 
43 // MIST名前空間を定義するためのマクロ
44 #ifndef _MIST_BEGIN
45 
46 
47 
48 
49 
50 #define _MIST_BEGIN namespace mist{
51 #endif
52 
53 #ifndef _MIST_END
54 #define _MIST_END }
55 #endif
56 
57 
58 
59 // mist名前空間の始まり
61 
62 
63 
64 // Microsoft Visual C++ のバージョンをチェック
65 #if defined( _MSC_VER )
66  #if _MSC_VER <= 1200
67  // Visual C++6.0
68  #define __MIST_MSVC__ 6
69  #elif _MSC_VER < 1400
70  // Visual Studio .NET 2002 - 2003バージョン
71  #define __MIST_MSVC__ 7
72  #else
73  // Visual Studio 2005 バージョン
74  #define __MIST_MSVC__ 8
75  #endif
76 #endif
77 
78 
79 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ >= 8
80  // セキュリティ上の理由で、sprintf や fopen などの関数呼び出しが警告となる問題への対処
81  // ここでの設定は、MISTをインクルードするすべてのファイルに影響があります
82  //
83  // 次のいずれかを選択する
84 
85  // 挙動が不明なので、今のところ警告を無視する
86  #pragma warning( disable : 4996 )
87 
88  //#undef _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES
89  //#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 0
91  //#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
92  //#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 // セキュリティが強化された関数を利用する(実行に時間が必要となる可能性あり)
93 #endif
94 
95 // Microsoft Windows かどうかをチェック
96 #if defined( WIN64 ) || defined( _WIN64 )
97  // 64bit Windows
98  #define __MIST_WINDOWS__ 2
99 #elif defined( WIN32 ) || defined( _WIN32 )
100  // 32bit Windows
101  #define __MIST_WINDOWS__ 1
102 #endif
103 
104 #if defined( _WIN64 ) || defined( __x86_64__ ) || defined( __AMD64__ )
105  // 64bit OS
106  #define __MIST64__ 64
107 #else
108  // 32bit OS
109  #define __MIST32__ 32
110 #endif
111 
112 
113 
114 // Microsoft Visual C++ 6.0 では,static const を未サポートのため,enum で代用する
115 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ <= 6
116  #define _MIST_CONST( type, name, value ) enum{ name = value }
117 #else
118  #define _MIST_CONST( type, name, value ) static const type name = value
119 #endif
120 
121 
122 // 構造体のアライメントを合わせるためのマクロ
123 #if defined(__MIST_MSVC__) || defined(__INTEL_COMPILER)
124  #define _MIST_PACKED
125 #else
126  #define _MIST_PACKED __attribute__( ( packed ) )
127 #endif
128 
129 
130 
131 // MISTヘッダ内で利用する設定
132 #define _MIST_ALLOCATE_TEST_ 0
133 
134 //#ifdef __MIST_MSVC__
135 // #define _MIST_ALLOCATOR_MEMORY_TRIM_ 0 ///< VC標準のSTLではサポートしていないのでオフにする
136 //#else
137 // #define _MIST_ALLOCATOR_MEMORY_TRIM_ 1 ///< VC以外のSTLではサポートしているのでオンにする
138 //#endif
139 
140 #define _MIST_ALLOCATOR_MEMORY_TRIM_ 0
141 
142 #define _MIST_UNUSED_( arg ) ( void )( arg )
143 
144 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ <= 6
145 
146 
147 // mist名前空間の終わり
148 _MIST_END
149 
150  #include <cmath>
151 
152  // VC6では、STD名前空間にABS関数等が入っていない問題を修正
153  #define STD_CMATH_FUNC1( name, func, value ) inline value name ( value v ){ return( ::func( v ) ); }
154  #define STD_CMATH_FUNC2( name, func, value ) inline value name ( value v1, value v2 ){ return( ::func( v1, v2 ) ); }
155  namespace std
156  {
157  STD_CMATH_FUNC1( abs, abs, int )
158  STD_CMATH_FUNC1( abs, labs, long )
159  STD_CMATH_FUNC1( abs, fabs, double )
160  STD_CMATH_FUNC1( sqrt, sqrt, double )
161  STD_CMATH_FUNC1( sin, sin, double )
162  STD_CMATH_FUNC1( cos, cos, double )
163  STD_CMATH_FUNC1( log, log, double )
164  STD_CMATH_FUNC1( log10, log10, double )
165  STD_CMATH_FUNC1( exp, exp, double )
166  STD_CMATH_FUNC2( pow, pow, double )
167  }
168  #undef STD_CMATH_FUNC1
169  #undef STD_CMATH_FUNC2
170 
171 // mist名前空間の始まり
173 
174 #endif
175 
176 
184 
185 
186 #ifndef _MIST_USER_CONFIG_
187 
188 #if !defined( NDEBUG ) || defined( DEBUG )
189 
190  // デバッグ用の設定を全てオンにする
191  #define _CHECK_ACCESS_VIOLATION_ 1
192  #define _CHECK_ARRAY_OPERATION_ 1
193  #define _CHECK_ARRAY1_OPERATION_ 1
194  #define _CHECK_ARRAY2_OPERATION_ 1
195  #define _CHECK_ARRAY3_OPERATION_ 1
196 
197  #define _CHECK_MATRIX_OPERATION_ 1
198 
199 #else
200 
201  // デバッグ用の設定を全てオフにする
202  #define _CHECK_ACCESS_VIOLATION_ 0
203  #define _CHECK_ARRAY_OPERATION_ 0
204  #define _CHECK_ARRAY1_OPERATION_ 0
205  #define _CHECK_ARRAY2_OPERATION_ 0
206  #define _CHECK_ARRAY3_OPERATION_ 0
207 
208  #define _CHECK_MATRIX_OPERATION_ 0
209 
210 #endif
211 
212 
213 #define __CHECK_HARD_CASE__ 0
214 
215 #define _ARRAY_BIND_OPERATION_SUPPORT_ 1
216 #define _ARRAY1_BIND_OPERATION_SUPPORT_ 1
217 #define _ARRAY2_BIND_OPERATION_SUPPORT_ 1
218 #define _ARRAY3_BIND_OPERATION_SUPPORT_ 1
219 
220 
221 #define _MIST_THREAD_SUPPORT_ 1
222 
223 #define _MIST_VECTOR_SUPPORT_ 0
224 
225 #define _LZW_COMPRESSION_SUPPORT_ false
226 
227 #define _COMPRESSED_CSV_SUPPORT_ 0
228 
229 
230 // 行列演算のオプション
231 #define _USE_INTEL_MATH_KERNEL_LIBRARY_ 0
232 #define _DESCENDING_ORDER_EIGEN_VALUE_ 0
233 #define _USE_BALANCING_MATRIX_EIGEN_ 1
234 #define _USE_DIVIDE_AND_CONQUER_SVD_ 1
235 
236 #endif
237 
238 
240 // MIST全般で利用される設定の終わり
241 
242 
251 template < class Object1, class Object2 >
252 inline bool is_same_object( const Object1 &o1, const Object2 &o2 )
253 {
254  return( reinterpret_cast< const void * >( &o1 ) == reinterpret_cast< const void * >( &o2 ) );
255 }
256 
263 inline const std::string wstr2str( const std::wstring &src )
264 {
265  static bool is_initialized = false;
266  if( !is_initialized )
267  {
268  is_initialized = true;
269  setlocale( LC_CTYPE, "" );
270  }
271 
272  size_t nbytes = wcstombs( NULL, src.c_str( ), 0 );
273  char *buff = new char[ nbytes + 1 ];
274  wcstombs( buff, src.c_str( ), nbytes + 1 );
275  std::string dst( buff );
276  delete [] buff;
277  return( dst );
278 }
279 
280 
281 
289 
290 
298 {
306  bool operator()( long double /* percent */ ) const { return( true ); }
307 };
308 
309 
316 template < class Functor >
318 {
319  Functor f_;
320  double lower_;
321  double upper_;
322 
330  bool operator()( long double percent )
331  {
332  percent = lower_ + percent / 100.0 * ( upper_ - lower_ );
333  return( f_( percent ) );
334  }
335 
336  __mist_convert_callback__( ) : lower_( 0.0 ), upper_( 100.0 ){ }
337  __mist_convert_callback__( Functor f, double l = 0.0, double u = 100.0 ) : f_( f ), lower_( l ), upper_( u ){ }
338 };
339 
340 
348 {
349 private:
350  int __percent__;
351 
352 public:
354  __mist_console_callback__( ) : __percent__( -1 )
355  {
356  }
357 
365  bool operator()( long double percent )
366  {
367  int ppp = static_cast< int >( percent );
368  if( __percent__ != ppp )
369  {
370  __percent__ = ppp;
371 
372  int k3 = static_cast< int >( percent / 100.0 );
373  percent -= k3 * 100.0;
374  int k2 = static_cast< int >( percent / 10.0 );
375  percent -= k2 * 10.0;
376  int k1 = static_cast< int >( percent );
377 
378  std::cerr << "busy... ";
379  if( k3 == 0 )
380  {
381  std::cerr << " ";
382  if( k2 == 0 )
383  {
384  std::cerr << " " << k1;
385  }
386  else
387  {
388  std::cerr << k2 << k1;
389  }
390  }
391  else
392  {
393  std::cerr << 1 << k2 << k1;
394  }
395  if( percent > 100.0 )
396  {
397  std::cerr << "%" << std::endl;
398  }
399  else
400  {
401  std::cerr << "%\r";
402  }
403  }
404  return( true );
405  }
406 };
407 
408 
409 
410 
422 {
424  {
425  std::cerr << "0% 10 20 30 40 50 60 70 80 90 100%" << std::endl;
426  std::cerr << "|----|----|----|----|----|----|----|----|----|----|" << std::endl;
427  }
428 
436  bool operator()( long double percent ) const
437  {
438  if( percent > 100.0 )
439  {
440  std::cerr << "***************************************************" << std::endl;
441  }
442  else
443  {
444  int i, p = static_cast< int >( percent / 2.0 );
445 
446  for( i = 0 ; i < p ; i++ )
447  {
448  std::cerr << "*";
449  }
450  for( ; i < 51 ; i++ )
451  {
452  std::cerr << " ";
453  }
454 
455  std::cerr << "\r";
456  }
457 
458  return( true );
459  }
460 };
461 
462 
463 
465 // MIST全般で利用できるコールバック関数
466 
467 
468 
469 #if _CHECK_ACCESS_VIOLATION_
470 
475  inline void mist_debug_assertion( ptrdiff_t index )
476  {
477  ::std::cerr << "Access Violation at ( " << static_cast< int >( index ) << " )" << ::std::endl;
478  }
479 
480 
486  inline void mist_debug_assertion( ptrdiff_t index1, ptrdiff_t index2 )
487  {
488  ::std::cerr << "Access Violation at ( " << static_cast< int >( index1 ) << ", " << static_cast< int >( index2 ) << " )" << ::std::endl;
489  }
490 
491 
498  inline void mist_debug_assertion( ptrdiff_t index1, ptrdiff_t index2, ptrdiff_t index3 )
499  {
500  ::std::cerr << "Access Violation at ( " << static_cast< int >( index1 ) << ", " << static_cast< int >( index2 ) << ", " << static_cast< int >( index3 ) << " )" << ::std::endl;
501  }
502 
503 
504  #define _CHECK_ACCESS_VIOLATION1U_( index ) \
505  if( index >= size( ) )\
506  {\
507  static value_type dmy;\
508  mist_debug_assertion( index );\
509  return( dmy );\
510  }
511 
512  #define _CHECK_ACCESS_VIOLATION1S_( index ) \
513  if( index < 0 || index >= size( ) )\
514  {\
515  static value_type dmy;\
516  mist_debug_assertion( index );\
517  return( dmy );\
518  }
519 
520  #define _CHECK_ACCESS_VIOLATION2U_( index1, index2 ) \
521  if( index1 >= size1( ) || index2 >= size2( ) )\
522  {\
523  static value_type dmy;\
524  mist_debug_assertion( index1, index2 );\
525  return( dmy );\
526  }
527 
528  #define _CHECK_ACCESS_VIOLATION2S_( index1, index2 ) \
529  if( index1 < 0 || index1 >= size1( ) || index2 < 0 || index2 >= size2( ) )\
530  {\
531  static value_type dmy;\
532  mist_debug_assertion( index1, index2 );\
533  return( dmy );\
534  }
535 
536  #define _CHECK_ACCESS_VIOLATION3U_( index1, index2, index3 ) \
537  if( index1 >= size1( ) || index2 >= size2( ) || index3 >= size3( ) )\
538  {\
539  static value_type dmy;\
540  mist_debug_assertion( index1, index2, index3 );\
541  return( dmy );\
542  }
543 
544  #define _CHECK_ACCESS_VIOLATION3S_( index1, index2, index3 ) \
545  if( index1 < 0 || index1 >= size1( ) || index2 < 0 || index2 >= size2( ) || index3 < 0 || index3 >= size3( ) )\
546  {\
547  static value_type dmy;\
548  mist_debug_assertion( index1, index2, index3 );\
549  return( dmy );\
550  }
551 
552 #else
553 
554  #define _CHECK_ACCESS_VIOLATION1U_( index )
555  #define _CHECK_ACCESS_VIOLATION1S_( index )
556  #define _CHECK_ACCESS_VIOLATION2U_( index1, index2 )
557  #define _CHECK_ACCESS_VIOLATION2S_( index1, index2 )
558  #define _CHECK_ACCESS_VIOLATION3U_( index1, index2, index3 )
559  #define _CHECK_ACCESS_VIOLATION3S_( index1, index2, index3 )
560 
561 #endif
562 
563 
564 
565 /*** Doxygen 用のメインページ ***********************************************************************************************/
747 // mist名前空間の終わり
748 _MIST_END
749 
750 
751 #endif
752 

Generated on Wed Nov 12 2014 19:44:20 for MIST by doxygen 1.8.1.2