ROSE  0.9.9.109
Sawyer.h
1 // WARNING: Changes to this file must be contributed back to Sawyer or else they will
2 // be clobbered by the next update from Sawyer. The Sawyer repository is at
3 // https://github.com/matzke1/sawyer.
4 
5 
6 
7 
8 #ifndef Sawyer_H
9 #define Sawyer_H
10 
11 #include <boost/cstdint.hpp>
12 #include <boost/thread/recursive_mutex.hpp>
13 #include <cstdio>
14 #include <string>
15 
301 // Version numbers (conditional compiliation is only so we can test version mismatch handling)
302 #ifndef SAWYER_VERSION_MAJOR
303 #define SAWYER_VERSION_MAJOR 0
304 #define SAWYER_VERSION_MINOR 1
305 #define SAWYER_VERSION_PATCH 0
306 #endif
307 
308 // Macros for thread-safety portability. This allows Sawyer to be compiled with or without thread support and not have a huge
309 // proliferation of conditional compilation directives in the main body of source code.
310 #ifdef _REENTRANT
311  #define SAWYER_MULTI_THREADED 1
312  #define SAWYER_THREAD_TAG Sawyer::MultiThreadedTag
313 #else
314  #define SAWYER_MULTI_THREADED 0
315  #define SAWYER_THREAD_TAG Sawyer::SingleThreadedTag
316 #endif
317 #define SAWYER_THREAD_TRAITS Sawyer::SynchronizationTraits<SAWYER_THREAD_TAG>
318 
319 #ifdef _REENTRANT
320  #if __cplusplus >= 201103L
321  #define SAWYER_THREAD_LOCAL thread_local
322  #elif defined(_MSC_VER)
323  // Visual C++, Intel (Windows), C++ Builder, Digital Mars C++
324  #define SAWYER_THREAD_LOCAL __declspec(thread)
325  #else
326  // Solaris Studio, IBM XL, GNU, LLVM, Intel (linux)
327  #define SAWYER_THREAD_LOCAL __thread
328  #endif
329 #else
330  #define SAWYER_THREAD_LOCAL /*void*/
331 #endif
332 
333 #ifdef BOOST_WINDOWS
334 // FIXME[Robb Matzke 2014-06-18]: get rid of ROSE_UTIL_EXPORTS; cmake can only have one DEFINE_SYMBOL
335 # if defined(SAWYER_DO_EXPORTS) || defined(ROSE_UTIL_EXPORTS) // defined in CMake when compiling libsawyer
336 # define SAWYER_EXPORT __declspec(dllexport)
337 # if _MSC_VER
338 # define SAWYER_EXPORT_NORETURN __declspec(dllexport noreturn)
339 # else
340  // MinGW complains about __declspec(dllexport noreturn), so use only __declspec(dllexport) instead.
341 # define SAWYER_EXPORT_NORETURN __declspec(dllexport)
342 # endif
343 # else
344 # define SAWYER_EXPORT __declspec(dllimport)
345 # define SAWYER_EXPORT_NORETURN __declspec(noreturn)
346 # endif
347 #else
348 # define SAWYER_EXPORT /*void*/
349 # define SAWYER_EXPORT_NORETURN /*void*/
350 #endif
351 
352 #define SAWYER_LINKAGE_INFO SAWYER_VERSION_MAJOR, SAWYER_VERSION_MINOR, SAWYER_VERSION_PATCH, SAWYER_MULTI_THREADED
353 #define SAWYER_CHECK_LINKAGE Sawyer::initializeLibrary(SAWYER_LINKAGE_INFO)
354 
355 
358 namespace Sawyer {
359 
365 SAWYER_EXPORT bool initializeLibrary(size_t vmajor=SAWYER_VERSION_MAJOR,
366  size_t vminor=SAWYER_VERSION_MINOR,
367  size_t vpatch=SAWYER_VERSION_PATCH,
368  bool withThreads=SAWYER_MULTI_THREADED);
369 
373 SAWYER_EXPORT boost::int64_t strtoll(const char*, char**, int);
374 
378 SAWYER_EXPORT boost::uint64_t strtoull(const char*, char**, int);
379 
383 SAWYER_EXPORT std::string readOneLine(FILE*);
384 
386 SAWYER_EXPORT FILE *popen(const std::string&, const char *how);
387 
389 SAWYER_EXPORT int pclose(FILE*);
390 
394 SAWYER_EXPORT std::string generateSequentialName(size_t length=3);
395 
397 SAWYER_EXPORT void checkBoost();
398 
400 SAWYER_EXPORT std::string thisExecutableName();
401 
402 } // namespace
403 
404 // Define only when we have the Boost Chrono library, which was first available in boost-1.47.
405 //#define SAWYER_HAVE_BOOST_CHRONO
406 
407 
409 // Compiler portability issues
410 //
411 // The following macros are used to distinguish between different compilers:
412 // _MSC_VER Defined only when compiled by Microsoft's MVC C++ compiler. This macro is predefined by Microsoft's
413 // preprocessor.
414 //
415 // The following macros are used to distinguish between different target environments, regardless of what compiler is being
416 // used or the environment which is doing the compiling. For instance, BOOST_WINDOWS will be defined when using the MinGW
417 // compiler on Linux to target a Windows environment.
418 // BOOST_WINDOWS The Windows API is present. This is defined (or not) by including <boost/config.hpp>.
419 //
421 
422 // Suppress warnings about unused function formal arguments. Most of the time you can simply omit the argument name, but that's
423 // not possible if the argument is integral to the documentation. In those cases, mention the argument with this macro.
424 # define SAWYER_ARGUSED(X) (void)(X)
425 
426 #ifdef _MSC_VER
427 //--------------------------
428 // Microsoft Windows
429 //--------------------------
430 
431 # define SAWYER_ATTR_UNUSED /*void*/
432 # define SAWYER_ATTR_NORETURN /*void*/
433 # define SAWYER_PRETTY_FUNCTION __FUNCSIG__
434 # define SAWYER_MAY_ALIAS /*void*/
435 # define SAWYER_STATIC_INIT /*void*/
436 # define SAWYER_DEPRECATED(WHY) /*void*/
437 
438 // Microsoft compiler doesn't support stack arrays whose size is not known at compile time. We fudge by using an STL vector,
439 // which will be cleaned up propertly at end of scope or exceptions.
440 # define SAWYER_VARIABLE_LENGTH_ARRAY(TYPE, NAME, SIZE) \
441  std::vector<TYPE> NAME##Vec_(SIZE); \
442  TYPE *NAME = &(NAME##Vec_[0]);
443 
444 #elif defined(__APPLE__) && defined(__MACH__)
445 //--------------------------
446 // Apple OSX, iOS, Darwin
447 //--------------------------
448 
449 # define SAWYER_ATTR_UNUSED /*void*/
450 # define SAWYER_ATTR_NORETURN /*void*/
451 # define SAWYER_PRETTY_FUNCTION __PRETTY_FUNCTION__
452 # define SAWYER_MAY_ALIAS /*void*/
453 # define SAWYER_STATIC_INIT /*void*/
454 # define SAWYER_DEPRECATED(WHY) /*void*/
455 
456 // Apple compilers doesn't support stack arrays whose size is not known at compile time. We fudge by using an STL vector,
457 // which will be cleaned up propertly at end of scope or exceptions.
458 # define SAWYER_VARIABLE_LENGTH_ARRAY(TYPE, NAME, SIZE) \
459  std::vector<TYPE> NAME##Vec_(SIZE); \
460  TYPE *NAME = &(NAME##Vec_[0]);
461 
462 
463 #else
464 //--------------------------
465 // Other, GCC-based
466 //--------------------------
467 
468 # define SAWYER_ATTR_UNUSED __attribute__((unused))
469 # define SAWYER_ATTR_NORETURN __attribute__((noreturn))
470 # define SAWYER_PRETTY_FUNCTION __PRETTY_FUNCTION__
471 # define SAWYER_MAY_ALIAS __attribute__((may_alias))
472 # define SAWYER_DEPRECATED(WHY) __attribute__((deprecated))
473 
474 // Sawyer globals need to be initialized after the C++ standard runtime, but before other user-level stuff. The constant 101
475 // causes the initialization to happen as early as possible after the C++ runtime.
476 # define SAWYER_STATIC_INIT __attribute__((init_priority(101)))
477 
478 # define SAWYER_VARIABLE_LENGTH_ARRAY(TYPE, NAME, SIZE) \
479  TYPE NAME[SIZE];
480 
481 #endif
482 
483 #define SAWYER_CONFIGURED /*void*/
484 
485 #endif
int pclose(FILE *)
Semi-portable replacement for pclose.
std::string readOneLine(FILE *)
Reads one line of input from a file.
FILE * popen(const std::string &, const char *how)
Semi-portable replacement for popen.
std::string thisExecutableName()
Return the name of this program obtained from the operating system.
std::string generateSequentialName(size_t length=3)
Generate a sequential name.
Name space for the entire library.
Definition: Access.h:11
void checkBoost()
Check for valid boost version or abort.
boost::uint64_t strtoull(const char *, char **, int)
Portable replacement for strtoull.
boost::int64_t strtoll(const char *, char **, int)
Portable replacement for strtoll.
bool initializeLibrary(size_t vmajor=0, size_t vminor=1, size_t vpatch=0, bool withThreads=0)
Explicitly initialize the library.