ROSE  0.11.145.0
Namespaces | Classes | Typedefs | Functions
Sawyer Namespace Reference

Description

Name space for the entire library.

All Sawyer functionality except for some C preprocessor macros exists inside this namespace. Most of the macros begin with the string "SAWYER_".

Namespaces

 Assert
 Run-time logic assertions.
 
 Attribute
 Attributes attached to other objects.
 
 Boost
 Boost Graph Library API for Sawyer::Container::Boost.
 
 CommandLine
 Parses program command line switches and arguments.
 
 Container
 Container classes that store user-defined values.
 
 Document
 Documentation-related entities.
 
 FileSystem
 File system utilities.
 
 Message
 Formatted diagnostic messages emitted to various backends.
 
 ProgressBarSettings
 Global settings for progress bars.
 
 Tree
 Tree data structure.
 
 Type
 Data types.
 
 Yaml
 YAML parser and unparser.
 

Classes

class  BitFlags
 Stores a vector of enum bit flags. More...
 
class  Cached
 Implements cache data members. More...
 
class  Callbacks
 
class  DefaultAllocator
 Default allocator. More...
 
class  Error
 Error value. More...
 
class  Error< char[N]>
 
struct  is_invocable
 
class  LockGuard2
 Locks multiple mutexes. More...
 
class  LockGuard2< NullMutex >
 
class  MultiInstanceTls
 Thread local data per object instance. More...
 
struct  MultiThreadedTag
 Tag indicating that an algorithm or API should assume multiple threads. More...
 
class  Nothing
 Represents no value. More...
 
class  NullBarrier
 
class  NullLockGuard
 
class  NullMutex
 
class  Ok
 Success value. More...
 
class  Ok< char[N]>
 
class  Optional
 Holds a value or nothing. More...
 
class  PoolAllocatorBase
 Small object allocation from memory pools. More...
 
class  ProgressBar
 Progress bars. More...
 
class  ProgressBarImpl
 
class  ProxyAllocator
 Allocator proxy. More...
 
class  Result
 Result containing a value or an error. More...
 
class  SharedFromThis
 Creates SharedPointer from this. More...
 
class  SharedObject
 Base class for reference counted objects. More...
 
class  SharedPointer
 Reference-counting intrusive smart pointer. More...
 
struct  SingleThreadedTag
 Tag indicating that an algorithm or API can assume only a single thread. More...
 
class  SmallObject
 Small object support. More...
 
class  StackAllocator
 Stack-like allocator. More...
 
class  Stopwatch
 Simple elapsed time. More...
 
struct  SynchronizationTraits
 Traits for thread synchronization. More...
 
struct  SynchronizationTraits< MultiThreadedTag >
 
struct  SynchronizationTraits< SingleThreadedTag >
 
class  TemporaryCallback
 
class  ThreadWorkers
 Work list with dependencies. More...
 
class  Time
 Represents an ISO 8601 time point. More...
 
class  WorkFifo
 First-in-first-out work queue. More...
 

Typedefs

typedef PoolAllocatorBase< sizeof(void *), 4, 32, 40960, SingleThreadedTagUnsynchronizedPoolAllocator
 Small object allocation from memory pools. More...
 
typedef PoolAllocatorBase< sizeof(void *), 4, 32, 40960, MultiThreadedTagSynchronizedPoolAllocator
 Small object allocation from memory pools. More...
 

Functions

template<typename T , typename U >
bool operator== (const Optional< T > &lhs, const U &rhs)
 
template<typename T , typename U >
bool operator!= (const Optional< T > &lhs, const U &rhs)
 
template<class IntegralType >
Sawyer::Optional< typename std::enable_if< std::is_integral< IntegralType >::value, IntegralType >::type > toDigit (char ch, IntegralType radix=10)
 Convert a character to a numeric digit. More...
 
template<class IntegralType >
std::enable_if< std::is_integral< IntegralType >::value, Sawyer::Result< IntegralType, std::string > >::type parse (const std::string &s)
 Safely convert a string to a number. More...
 
template<class T >
Ok< T > makeOk (const T &value)
 Conventient way to constructo an Ok value before C++17. More...
 
Ok< std::string > makeOk (const char *s)
 
Ok< std::string > makeOk (char *s)
 
template<class T >
Error< T > makeError (const T &value)
 Conventient way to constructo an Error value before C++17. More...
 
Error< std::string > makeError (const char *s)
 
Error< std::string > makeError (char *s)
 
bool initializeLibrary (size_t vmajor=0, size_t vminor=1, size_t vpatch=0, bool withThreads=0)
 Explicitly initialize the library. More...
 
boost::int64_t strtoll (const char *, char **, int)
 Portable replacement for strtoll. More...
 
boost::uint64_t strtoull (const char *, char **, int)
 Portable replacement for strtoull. More...
 
std::string readOneLine (FILE *)
 Reads one line of input from a file. More...
 
FILE * popen (const std::string &, const char *how)
 Semi-portable replacement for popen. More...
 
int pclose (FILE *)
 Semi-portable replacement for pclose. More...
 
std::string generateSequentialName (size_t length=3)
 Generate a sequential name. More...
 
void checkBoost ()
 Check for valid boost version or abort. More...
 
std::string thisExecutableName ()
 Return the name of this program obtained from the operating system. More...
 
template<class Pointer >
Pointer::Pointee * getRawPointer (Pointer &ptr)
 
template<class T >
void clear (SharedPointer< T > &ptr)
 Make pointer point to nothing. More...
 
std::ostream & operator<< (std::ostream &, const Stopwatch &)
 
Sawyer::SynchronizationTraits< Sawyer::SingleThreadedTag >::RecursiveMutex & bigMutex ()
 
size_t fastRandomIndex (size_t n, size_t seed=0)
 Thread-safe random number generator. More...
 
std::ostream & operator<< (std::ostream &, const Time &)
 
template<class WorkItems , class Functor >
void processWorkList (WorkItems &workList, size_t maxWorkers, Functor f)
 Process work from a work list in parallel. More...
 
template<class DependencyGraph , class Functor >
void workInParallel (const DependencyGraph &dependencies, size_t nWorkers, Functor functor)
 Performs work in parallel. More...
 
template<class DependencyGraph , class Functor , class Monitor >
void workInParallel (const DependencyGraph &dependencies, size_t nWorkers, Functor functor, Monitor monitor, boost::chrono::milliseconds period)
 Performs work in parallel. More...
 

Typedef Documentation

Small object allocation from memory pools.

Thread safety: This allocator is not thread safe; the caller must synchronize to prevent concurrent calls.

See PoolAllocatorBase for details.

Definition at line 514 of file PoolAllocator.h.

Small object allocation from memory pools.

Thread safety: This allocator is thread safe.

See PoolAllocatorBase for details.

Definition at line 521 of file PoolAllocator.h.

Function Documentation

template<class IntegralType >
Sawyer::Optional<typename std::enable_if<std::is_integral<IntegralType>::value, IntegralType>::type> Sawyer::toDigit ( char  ch,
IntegralType  radix = 10 
)

Convert a character to a numeric digit.

If the character is valid for the specified radix, then its numeric value is returned, otherwise nothing is returned. The radix must be less than or equal to 16.

Definition at line 27 of file Parse.h.

Referenced by Sawyer::Yaml::parse().

template<class IntegralType >
std::enable_if<std::is_integral<IntegralType>::value, Sawyer::Result<IntegralType, std::string> >::type Sawyer::parse ( const std::string &  s)

Safely convert a string to a number.

Parse YAML from string.

The input string must parse as a integer without leading white space and without trailing characters. For signed integer types, the integer may be immediately preceded by a minus ("-") or plus ("+") sign. The integer part may be preceded by a radix indicator: "0x" for hexadecimal or "0b" for binary. Octal and other bases are not supported. Digits may be separated from one another (or from the radix specifier) by a single underscore, as in "0b_0001_0010_0011_0100_0101_0110_0111_1000".

The IntegralType must be a signed or unsigned integer type of any width. The uint8_t and int8_t types are also accepted although they're aliases for unsigned char and signed char .

If a syntax error occurs, or if the magnitude of the value is too large to be represented by the specified IntegralType, then an error message is returned. The text of the message begins with either "syntax error:" or "overflow error:".

Definition at line 60 of file Parse.h.

References toDigit().

template<class T >
Ok<T> Sawyer::makeOk ( const T &  value)

Conventient way to constructo an Ok value before C++17.

Template parameter type deduction in constructors first appeared in C++17. The standard library worked around this by using factory functions to instantiate these types without having to repeat the full type name.

Definition at line 135 of file Result.h.

template<class T >
Error<T> Sawyer::makeError ( const T &  value)

Conventient way to constructo an Error value before C++17.

Template parameter type deduction in constructors first appeared in C++17. The standard library worked around this by using factory functions to instantiate these types without having to repeat the full type name.

Definition at line 256 of file Result.h.

bool Sawyer::initializeLibrary ( size_t  vmajor = 0,
size_t  vminor = 1,
size_t  vpatch = 0,
bool  withThreads = 0 
)

Explicitly initialize the library.

This initializes any global objects provided by the library to users. This happens automatically for many API calls, but sometimes needs to be called explicitly. It can be called as often as desired; each call checks caller-callee consistency (version number and configuration), but only the first call does any initialization. The function always returns true.

Referenced by Sawyer::CommandLine::SwitchGroup::SwitchGroup().

boost::int64_t Sawyer::strtoll ( const char *  ,
char **  ,
int   
)

Portable replacement for strtoll.

Microsoft doesn't define this function, so we define it in the Sawyer namespace.

boost::uint64_t Sawyer::strtoull ( const char *  ,
char **  ,
int   
)

Portable replacement for strtoull.

Microsoft doesn't define this function, so we define it in the Sawyer namespace.

std::string Sawyer::readOneLine ( FILE *  )

Reads one line of input from a file.

Returns one line, including any line termination. Returns an empty string at the end of the file.

FILE* Sawyer::popen ( const std::string &  ,
const char *  how 
)

Semi-portable replacement for popen.

int Sawyer::pclose ( FILE *  )

Semi-portable replacement for pclose.

std::string Sawyer::generateSequentialName ( size_t  length = 3)

Generate a sequential name.

A new string is generated each time this is called.

void Sawyer::checkBoost ( )

Check for valid boost version or abort.

Referenced by Sawyer::Attribute::Storage<>::attributeOrElse(), and Sawyer::Attribute::Storage<>::getAttribute().

std::string Sawyer::thisExecutableName ( )

Return the name of this program obtained from the operating system.

template<class T >
void Sawyer::clear ( SharedPointer< T > &  ptr)

Make pointer point to nothing.

Clears the pointer so it points to no object. A cleared pointer is like a default-constructed pointer.

Definition at line 342 of file SharedPointer.h.

size_t Sawyer::fastRandomIndex ( size_t  n,
size_t  seed = 0 
)

Thread-safe random number generator.

Generates uniformly distributed pseudo-random size_t values. The returned value is greater than zero and less than n, where n must be greater than zero except when seeding the sequence. To seed the sequence, call with n equal to zero and a non-zero seed; all other calls must supply a zero seed value. This function uses the fastest available method for returning random numbers in a multi-threaded environment. This function is thread-safe.

Referenced by Rose::Combinatorics::shuffle().

template<class DependencyGraph , class Functor >
void Sawyer::workInParallel ( const DependencyGraph &  dependencies,
size_t  nWorkers,
Functor  functor 
)

Performs work in parallel.

Creates up to the specified number of worker threads to run the tasks described in the dependencies graph (at least one thread, but not more than the number of items on which to work). The dependencies is a graph whose vertices represent individual tasks to be performed by worker threads, and whose edges represent dependencies between the task. An edge from task a to task b means that task b must complete before task a can begin. If the dependencies graph contains cycles then as much work as possible is performed and then a ContainsCycle exception is thrown.

The functor can be a class with operator(), a function pointer, or a lambda expression. If a class is used, it must be copyable and each worker thread will be given its own copy. The functor is invoked with two arguments: the ID number of the task being processed, and a reference to a copy of the task (vertex value) in the dependency graph. The ID number is the vertex ID number in the dependencies graph.

If a monitor is provided, it will be called once every period milliseconds with the following arguments: the dependencies graph, number of work items that have been completed, and the set of dependencies vertex IDs (std::set<size_t>) that are currently running.

The call does not return until all work has been completed.

Definition at line 316 of file ThreadWorkers.h.

template<class DependencyGraph , class Functor , class Monitor >
void Sawyer::workInParallel ( const DependencyGraph &  dependencies,
size_t  nWorkers,
Functor  functor,
Monitor  monitor,
boost::chrono::milliseconds  period 
)

Performs work in parallel.

Creates up to the specified number of worker threads to run the tasks described in the dependencies graph (at least one thread, but not more than the number of items on which to work). The dependencies is a graph whose vertices represent individual tasks to be performed by worker threads, and whose edges represent dependencies between the task. An edge from task a to task b means that task b must complete before task a can begin. If the dependencies graph contains cycles then as much work as possible is performed and then a ContainsCycle exception is thrown.

The functor can be a class with operator(), a function pointer, or a lambda expression. If a class is used, it must be copyable and each worker thread will be given its own copy. The functor is invoked with two arguments: the ID number of the task being processed, and a reference to a copy of the task (vertex value) in the dependency graph. The ID number is the vertex ID number in the dependencies graph.

If a monitor is provided, it will be called once every period milliseconds with the following arguments: the dependencies graph, number of work items that have been completed, and the set of dependencies vertex IDs (std::set<size_t>) that are currently running.

The call does not return until all work has been completed.

Definition at line 323 of file ThreadWorkers.h.

References Sawyer::ThreadWorkers< DependencyGraph, Functor >::nFinished(), Sawyer::ThreadWorkers< DependencyGraph, Functor >::runningTasks(), Sawyer::ThreadWorkers< DependencyGraph, Functor >::start(), and Sawyer::ThreadWorkers< DependencyGraph, Functor >::tryWaitFor().

template<class WorkItems , class Functor >
void Sawyer::processWorkList ( WorkItems &  workList,
size_t  maxWorkers,
Functor  f 
)

Process work from a work list in parallel.

Processes each item in the work list by passing the item and the list of pending work to the provided functor. Up to maxWorkers work items are processed in parallel. The workList is responsible for holding the list of outstanding work items and hands them out one at a time according some priority. The WorkFifo is an example class that satisfies the WorkItems interface and hands out work items in the same order they were created. Since the functor is given a reference to the workList, wihch contains all pending work (work that hasn't started yet), the functor is able to modify the work list, such as adding additional work items.

Definition at line 69 of file WorkList.h.