Board  0.9.4
Tools.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef _BOARD_TOOLS_H_
27 #define _BOARD_TOOLS_H_
28 
29 #include <iostream>
30 #include <ctime>
31 #include <cstring>
32 #include "Rect.h"
33 
34 #if defined( _MSC_VER )
35 #define secured_sprintf sprintf_s
36 #else
37 #define secured_sprintf snprintf
38 #endif // defined( _MSC_VER )
39 
40 namespace LibBoard {
41 
42 namespace Tools {
43 
44 enum CaseSensitivity { CaseSensitive, CaseInsensitive };
45 
50 public:
51 
52  inline MessageStream( std::ostream & out, const char * prefix );
53 
54  template<typename T>
55  inline MessageStream operator<<( const T & v );
56 
57  inline MessageStream operator<<( std::ostream & (*fun)(std::ostream &) );
58 
59 private:
60  std::ostream & _out;
61  const char * _prefix;
62 };
63 
64 extern MessageStream error;
65 extern MessageStream warning;
66 extern MessageStream notice;
67 
68 MessageStream::MessageStream( std::ostream & out, const char * prefix )
69  : _out( out ),
70  _prefix( prefix )
71 {
72 }
73 
74 template<typename T>
75 MessageStream MessageStream::operator<<( const T & v )
76 {
77  if ( _prefix ) {
78  _out << _prefix << v;
79  } else {
80  _out << v;
81  }
82  return MessageStream( _out, 0 );
83 }
84 
85 MessageStream MessageStream::operator<<( std::ostream & (*fun)(std::ostream &) )
86 {
87  if ( _prefix ) {
88  _out << _prefix << fun;
89  } else {
90  _out << fun;
91  }
92  return MessageStream( _out, 0 );
93 }
94 
95 
96 inline void secured_strncpy( char * dst, const char * src, size_t count );
97 
98 inline void secured_ctime( char * str, const time_t * t, size_t count );
99 
100 bool base64encode(std::istream & in, std::ostream & , int linesize = 80);
101 
102 bool stringEndsWith( const char * str, const char * end, CaseSensitivity sensitivity = CaseSensitive );
103 
104 void flushFile( const char * filename, std::ostream & out );
105 
106 Rect getEPSBoundingBox( const char * filename );
107 
108 bool canCreateFile( const char * filename );
109 
110 bool canReadFile( const char * filename );
111 
112 const char * temporaryFilename( const char * extension );
113 
114 unsigned int boardRand();
115 
116 } // namespace Tools
117 
118 } // namespace LibBoard
119 
120 #include "Tools.ih"
121 
122 #endif /* _SHAPE_H_ */
Definition: Board.h:41
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Definition: Tools.h:49