Evo C++ Library v0.5.1
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
sys.h File Reference

Evo implementation detail for system portability – this is included by most Evo headers, include this via: include <evo/type.h>. More...

#include "../evo_config.h"

Go to the source code of this file.

Classes

class  Exception
 Evo base exception class. More...
 
class  ExceptionFileIn
 File input stream exception for file read errors, see Exception. More...
 
class  ExceptionFileOpen
 File open exception for errors opening a file, see Exception. More...
 
class  ExceptionFileOut
 File output stream exception for file write errors, see Exception. More...
 
class  ExceptionStream
 Base stream exception for all stream errors, see Exception. More...
 
class  ExceptionStreamIn
 Input stream exception for stream read errors, see Exception. More...
 
class  ExceptionStreamOpen
 Stream open exception for errors opening a stream, see Exception. More...
 
class  ExceptionStreamOut
 Output stream exception for stream write errors, see Exception. More...
 
struct  ListBase< T, TSize >
 Base for all Evo list types (used internally). More...
 
struct  NewlineDefault
 Default newline type, implicitly converts to NL_SYS (system default newline). More...
 
class  NewlineValue
 Holds a Newline value that can be null, which implicitly converts to NL_SYS (system default newline). More...
 
struct  Null
 Null type. More...
 
struct  SysLinux
 
class  WorkBuffer< T >
 Working data buffer. More...
 

Namespaces

 evo
 Evo C++ Library namespace.
 

Macros

#define EVO_64   1
 Defined when current architecture is 64-bit, if not then EVO_32 is defined for 32-bit instead. More...
 
#define EVO_APPLE_CLANG_VER   901
 Apple clang compiler version as integer. More...
 
#define EVO_ARCH_BITS   64
 Number of bits for current architecture. More...
 
#define EVO_ATTRIB_UNUSED
 Mark variable with "unused" attribute to suppress "unused variable" compiler warnings on it. More...
 
#define EVO_CHAR_SIGNED   1
 Whether char is signed – usually true, but unsigned on some systems. More...
 
#define EVO_CLANG_VER   301
 Clang compiler version as integer (LLVM or Apple). More...
 
#define EVO_CNULL   ((const char*)0)
 Shortcut for NULL as const-char pointer. More...
 
#define EVO_COMPILER   "Unknown"
 C++ compiler name. More...
 
#define EVO_COMPILER_VER   0
 C++ compiler version integer. More...
 
#define EVO_CPP11
 Defined when compiler C++11 supported is enabled. More...
 
#define EVO_CPP14
 Defined when compiler C++14 supported is enabled. More...
 
#define EVO_CPP14_FULL
 
#define EVO_CPP17
 Defined when compiler C++17 supported is enabled. More...
 
#define EVO_CREATE_EXCEPTION(NAME, BASE)
 Create an Evo exception from a base exception. More...
 
#define EVO_CREATE_EXCEPTION_IMPL(NAME, BASE)   EVO_CREATE_EXCEPTION_IMPL_2(NAME, BASE, evo::errormsg)
 Create an Evo exception implementation. More...
 
#define EVO_CREATE_EXCEPTION_IMPL_2(NAME, BASE, ERRMSG_FUNC)
 Create an Evo exception implementation with custom errormsg() function. More...
 
#define EVO_EXCEPTIONS_ENABLED   1
 
#define EVO_GCC_VER   504
 GCC compiler version as integer. More...
 
#define EVO_LLVM_CLANG_VER   308
 LLVM clang compiler version as integer. More...
 
#define EVO_MSVC_NOWARN_END
 Set end point for ignoring MSVC warnings. More...
 
#define EVO_MSVC_NOWARN_START(CODES)
 Set starting point to ignore MSVC warnings. More...
 
#define EVO_MSVC_TOOLSET   141
 MSVC toolset version as integer (3 digits, 2 digits before MSVC 2010). More...
 
#define EVO_MSVC_YEAR   2017
 MSVC compiler year (4 digits). More...
 
#define EVO_NOEXCEPT   noexcept
 No-exceptions specification before and after C++11. More...
 
#define EVO_ONCPP11(EXPR)   EXPR
 Compile EXPR only if C++11 support is detected, otherwise this is a no-op. More...
 
#define EVO_ONCPP11_ELSE(EXPR1, EXPR2)   EXPR1
 Compile to EXPR1 if C++11 support is detected, otherwise compile to EXPR2. More...
 
#define EVO_ONCPP14(EXPR)   EXPR
 Compile EXPR only if C++14 support is detected, otherwise this is a no-op. More...
 
#define EVO_ONCPP14_FULL(EXPR)   EXPR
 Compile EXPR only if "full" C++14 support is detected, otherwise this is a no-op. More...
 
#define EVO_ONCPP17(EXPR)   EXPR
 Compile EXPR only if C++17 support is detected, otherwise this is a no-op. More...
 
#define EVO_PARAM_UNUSED(NAME)
 Mark function parameter as unused to suppress "unreferenced parameter" compiler warnings on it. More...
 
#define EVO_THREAD_LOCAL   thread_local
 Mark a variable for thread-local storage. More...
 
#define EVO_THROW(TYPE, MSG)   throw TYPE(__FILE__, __LINE__, MSG)
 Throw an Evo exception. More...
 
#define EVO_THROW_ERR(TYPE, MSG, ERROR)   throw TYPE(__FILE__, __LINE__, MSG, ERROR)
 Throw an Evo exception with error code. More...
 
#define EVO_THROW_ERR_CHECK(TYPE, MSG, ERROR, COND)   { if (COND) throw TYPE(__FILE__, __LINE__, MSG, ERROR); }
 Throw an Evo exception with error code if COND is true. More...
 
#define EVO_VNULL   ((void*)0)
 Shortcut for NULL as void-pointer. More...
 
#define INCL_evo_impl_sys_h
 

Typedefs

typedef uint32 SizeT
 Default Evo container size type. More...
 
typedef uint32 StrSizeT
 Default Evo string size type. More...
 

Enumerations

enum  Error {
  ENone = 0, EEnd, EMoreOutput, ENonBlock,
  EUnknown, ENotImpl, EInvalOp, EInval,
  EFail, ELoss, ERetry, EBufSize,
  EOutOfBounds, EClosed, ETimeout, ESignal,
  EPtr, ESpace, EAccess, EExist,
  ENotFound, ENotDir, ESize, ELimit,
  ELength, ERead, EWrite, EInput
}
 General Evo error code stored in exceptions, or used directly when exceptions are disabled. More...
 
enum  Flush { fFLUSH =0 }
 Signals an output stream to flush pending data. More...
 
enum  Newline { nLF =0, nCR, nCRLF, nLFCR }
 Newline type. More...
 
enum  ValAlgReverse { vREVERSE =0 }
 Special value type to reverse algorithm, pass as vREVERSE. More...
 
enum  ValEmpty { vEMPTY =0 }
 Special empty value type, pass as vEMPTY. More...
 
enum  ValNull { vNULL =0 }
 Unique null value type and value (vNULL). More...
 

Functions

const char * errormsg (Error error)
 Get general error message for error code. More...
 
template<class TOut >
TOut & errormsg_out (TOut &out, Error err)
 Write error message with errno to output stream/string. More...
 
const char * getnewline (Newline newline=NL)
 Get newline string for given type. More...
 
uint getnewlinesize (Newline newline=NL)
 Get newline string size for given type. More...
 
bool sleepms (ulong msec)
 Sleep for number of milliseconds. More...
 
bool sleepns (ulongl nsec)
 Sleep for number of nanoseconds. More...
 
bool sleepus (ulongl usec)
 Sleep for number of microseconds. More...
 
template<class T >
void swap (T &a, T &b)
 Swap contents of given objects. More...
 

Variables

static const NewlineDefault & NL = NewlineDefault()
 Default newline type. More...
 
static const Newline NL_SYS = nLF
 Current system newline type. More...
 

Detailed Description

Evo implementation detail for system portability – this is included by most Evo headers, include this via: include <evo/type.h>.

Macro Definition Documentation

◆ EVO_64

#define EVO_64   1

Defined when current architecture is 64-bit, if not then EVO_32 is defined for 32-bit instead.

◆ EVO_APPLE_CLANG_VER

#define EVO_APPLE_CLANG_VER   901

Apple clang compiler version as integer.

◆ EVO_ARCH_BITS

#define EVO_ARCH_BITS   64

Number of bits for current architecture.

◆ EVO_ATTRIB_UNUSED

#define EVO_ATTRIB_UNUSED

Mark variable with "unused" attribute to suppress "unused variable" compiler warnings on it.

  • Use this after the variable name in the variable declaration
  • This is mainly supported by GCC and Clang compilers, and is ignored by other compilers
Example
#include <evo/type.h>
int main() {
int myvar1 EVO_ATTRIB_UNUSED;
int myvar2 EVO_ATTRIB_UNUSED = 0;
return 0;
}

◆ EVO_CHAR_SIGNED

#define EVO_CHAR_SIGNED   1

Whether char is signed – usually true, but unsigned on some systems.

◆ EVO_CLANG_VER

#define EVO_CLANG_VER   301

Clang compiler version as integer (LLVM or Apple).

  • Note: Apple forked clang versions after clang 3.1

◆ EVO_COMPILER

#define EVO_COMPILER   "Unknown"

C++ compiler name.

◆ EVO_COMPILER_VER

#define EVO_COMPILER_VER   0

C++ compiler version integer.

  • Most version integers are calculated as: (major * 100) + minor
  • Some compilers will have additional macros with more info
  • Note: Not all compilers listed here are fully supported

Compiler versions:

Compiler Name Version Additional Macros
GCC 504 for GCC 5.4 EVO_GCC_VER
Clang 308 for Clang 3.8 EVO_LLVM_CLANG_VER / EVO_CLANG_VER
Apple Clang 901 for Apple Clang 9.1 – Apple forked clang versions after 3.1 EVO_APPLE_CLANG_VER / EVO_CLANG_VER
MSVC Visual Studio version: 1507 for 2017 15.7, 1400 for 2015 14.0 EVO_MSVC_YEAR / EVO_MSVC_TOOLSET
Intel 1700 for Intel C++ 17.00
C++ Builder 101 for C++ Builder 10.1, older: 1-8 for C++ Builder XE - XE8

◆ EVO_CPP11

#define EVO_CPP11

Defined when compiler C++11 supported is enabled.

◆ EVO_CPP14

#define EVO_CPP14

Defined when compiler C++14 supported is enabled.

◆ EVO_CPP14_FULL

#define EVO_CPP14_FULL

◆ EVO_CPP17

#define EVO_CPP17

Defined when compiler C++17 supported is enabled.

◆ EVO_CREATE_EXCEPTION

#define EVO_CREATE_EXCEPTION (   NAME,
  BASE 
)
Value:
class NAME : public BASE \
{ EVO_CREATE_EXCEPTION_IMPL(NAME, BASE) }
#define EVO_CREATE_EXCEPTION_IMPL(NAME, BASE)
Create an Evo exception implementation.
Definition: sys.h:1365

Create an Evo exception from a base exception.

  • This defines the exception class and the implementation
  • Note that tools like doxygen may not notice classes defined via macro, see EVO_CREATE_EXCEPTION_IMPL() for an alternative
Parameters
NAMEName of new exception type
BASEBase exception type – Exception or derived from it
Example
#include <evo/type.h>
EVO_CREATE_EXCEPTION(ExceptionFoo, Exception);

◆ EVO_CREATE_EXCEPTION_IMPL

#define EVO_CREATE_EXCEPTION_IMPL (   NAME,
  BASE 
)    EVO_CREATE_EXCEPTION_IMPL_2(NAME, BASE, evo::errormsg)

Create an Evo exception implementation.

  • This "pastes" the implementation for an Evo exception class
  • Use this to be explicit about creating the exception class, and so tools like doxygen see (and document) the class
  • This uses the default errormsg() function to format Error codes, use EVO_CREATE_EXCEPTION_IMPL_2() to override this
  • Alternatively, use EVO_CREATE_EXCEPTION() to create an Evo exception
Parameters
NAMEName of new exception type
BASEBase exception type – Exception or derived from it
Example
#include <evo/type.h>
class ExceptionFoo : public Exception {
EVO_CREATE_EXCEPTION_IMPL(ExceptionFoo, Exception)
};

◆ EVO_CREATE_EXCEPTION_IMPL_2

#define EVO_CREATE_EXCEPTION_IMPL_2 (   NAME,
  BASE,
  ERRMSG_FUNC 
)
Value:
public: \
NAME(const char* file, ulong line, const StringBase& msg, Error error=EUnknown) : BASE(file, line, #NAME, msg, error, ERRMSG_FUNC) { } \
NAME(const NAME& e) : BASE(e) { } \
protected: \
NAME(const char* file, ulong line, const char* type, const StringBase& msg, Error error, ErrorMsgFunc errormsg_func) : BASE(file, line, type, msg, error, errormsg_func) { }
Error
General Evo error code stored in exceptions, or used directly when exceptions are disabled...
Definition: sys.h:1113
String::ListBaseType StringBase
Base string typedef.
Definition: string.h:5372
Unknown or unspecified error.
Definition: sys.h:1120

Create an Evo exception implementation with custom errormsg() function.

Parameters
NAMEName of new exception type
BASEBase exception type – Exception or derived from it
ERRMSG_FUNCError message function to use to format Error code
Example
#include <evo/type.h>
class ExceptionFoo : public Exception {
EVO_CREATE_EXCEPTION_IMPL(ExceptionFoo, Exception)
};

◆ EVO_EXCEPTIONS_ENABLED

#define EVO_EXCEPTIONS_ENABLED   1

◆ EVO_GCC_VER

#define EVO_GCC_VER   504

GCC compiler version as integer.

◆ EVO_LLVM_CLANG_VER

#define EVO_LLVM_CLANG_VER   308

LLVM clang compiler version as integer.

◆ EVO_MSVC_NOWARN_END

#define EVO_MSVC_NOWARN_END

Set end point for ignoring MSVC warnings.

  • See EVO_MSVC_NOWARN_START()
  • Semicolon not needed after this
  • This is MSVC specific and is ignored by other compilers

◆ EVO_MSVC_NOWARN_START

#define EVO_MSVC_NOWARN_START (   CODES)

Set starting point to ignore MSVC warnings.

  • This must be followed by a matching EVO_MSVC_NOWARN_END at some point in the same file
  • Semicolon not needed after this
  • This is MSVC specific and is ignored by other compilers
Parameters
CODESSpace separated list of warning codes to disable (without the 'C' prefix) – see MSVC warning codes
Example
#include <evo/type.h>
// Disable unused parameter and unused variable warnings in MSVC
int main(int arg, char** argv) {
int myvar;
return 0;
}

◆ EVO_MSVC_TOOLSET

#define EVO_MSVC_TOOLSET   141

MSVC toolset version as integer (3 digits, 2 digits before MSVC 2010).

◆ EVO_MSVC_YEAR

#define EVO_MSVC_YEAR   2017

MSVC compiler year (4 digits).

◆ EVO_NOEXCEPT

#define EVO_NOEXCEPT   noexcept

No-exceptions specification before and after C++11.

  • This is replaced with either "noexcept" (C++11) or "throw()" (before C++11)

◆ EVO_ONCPP11

#define EVO_ONCPP11 (   EXPR)    EXPR

Compile EXPR only if C++11 support is detected, otherwise this is a no-op.

  • #include <evo/type.h>
  • This is useful to make code using C++11 features portable with and without C++11 support
  • Examples:
    #include <evo/type.h>
    // Function default template param not supported before C++11
    template<class T EVO_ONCPP11(=ulong)> void foo(T num) {
    };
    class Bar {
    public:
    Bar() { }
    private:
    // Disable copy constructor
    Bar(const Bar&) EVO_ONCPP11(= delete);
    };
Parameters
EXPRExpression to use if C++11 is supported

◆ EVO_ONCPP11_ELSE

#define EVO_ONCPP11_ELSE (   EXPR1,
  EXPR2 
)    EXPR1

Compile to EXPR1 if C++11 support is detected, otherwise compile to EXPR2.

  • #include <evo/type.h>
  • This is useful to make code using C++11 features portable with and without C++11 support
Parameters
EXPR1Expression to use if C++11 is supported
EXPR2Expression to use if C++11 is not supported

◆ EVO_ONCPP14

#define EVO_ONCPP14 (   EXPR)    EXPR

Compile EXPR only if C++14 support is detected, otherwise this is a no-op.

  • This is useful to specify constexpr when it improves code with C++14 support
Parameters
EXPRExpression to use if C++14 is supported

◆ EVO_ONCPP14_FULL

#define EVO_ONCPP14_FULL (   EXPR)    EXPR

Compile EXPR only if "full" C++14 support is detected, otherwise this is a no-op.

  • This is useful to specify constexpr when it improves code with C++14 support
  • This excludes MSVC before 2017 due to C++14 issues
Parameters
EXPRExpression to use if C++14 is fully supported

◆ EVO_ONCPP17

#define EVO_ONCPP17 (   EXPR)    EXPR

Compile EXPR only if C++17 support is detected, otherwise this is a no-op.

Parameters
EXPRExpression to use if C++17 is supported

◆ EVO_PARAM_UNUSED

#define EVO_PARAM_UNUSED (   NAME)

Mark function parameter as unused to suppress "unreferenced parameter" compiler warnings on it.

  • Use this at the top of the function implementation, end with a semicolon
  • This is mainly supported by MSVC, and is ignored by other compilers
Parameters
NAMEParameter name to mark as "unused"
Example
#include <evo/type.h>
void foo(int arg1, int arg2) {
}
int main() {
foo(1);
return 0;
}

◆ EVO_THREAD_LOCAL

#define EVO_THREAD_LOCAL   thread_local

Mark a variable for thread-local storage.

  • With C++11 this is the same as the "thread_local" keyword, but this also works on older compilers
  • Older compilers may only support POD or basic types as thread-local, depending on compiler version
Example
EVO_THREAD_LOCAL static int var;

◆ EVO_THROW

#define EVO_THROW (   TYPE,
  MSG 
)    throw TYPE(__FILE__, __LINE__, MSG)

Throw an Evo exception.

  • This passes the current source filename and line number to the exception
  • Alternatively, use EVO_THROW_ERR() to throw with an error code
  • If exceptions are disabled this calls abort()
Parameters
TYPEException type (Exception or derived from it)
MSGException message string (const char*)
Example
#include <evo/type.h>
#include <evo/io.h>
class ExceptionCustom : public Exception {
EVO_CREATE_EXCEPTION_IMPL(ExceptionCustom, Exception)
};
int main() {
try {
EVO_THROW(ExceptionCustom, "Error message");
return 0;
}

◆ EVO_THROW_ERR

#define EVO_THROW_ERR (   TYPE,
  MSG,
  ERROR 
)    throw TYPE(__FILE__, __LINE__, MSG, ERROR)

Throw an Evo exception with error code.

  • This passes the current source filename and line number to the exception
  • Alternatively, use EVO_THROW_ERR_CHECK() to throw on an error condition
  • If exceptions are disabled this calls abort()
Parameters
TYPEException type (Exception or derived from it)
MSGException message string (const char*)
ERRORError code – see Error
Example
#include <evo/type.h>
#include <evo/io.h>
class ExceptionCustom : public Exception {
EVO_CREATE_EXCEPTION_IMPL(ExceptionCustom, Exception)
};
int main() {
try {
EVO_THROW_ERR(ExceptionCustom, "Error message", EUnknown);
return 0;
}

◆ EVO_THROW_ERR_CHECK

#define EVO_THROW_ERR_CHECK (   TYPE,
  MSG,
  ERROR,
  COND 
)    { if (COND) throw TYPE(__FILE__, __LINE__, MSG, ERROR); }

Throw an Evo exception with error code if COND is true.

  • This passes the current source filename and line number to the exception
  • This only throws if COND evaluates to true
    • If exceptions are disabled this calls abort() instead of throw
Parameters
TYPEException type (Exception or derived from it)
MSGException message string (const char*)
ERRORError code – see Error
CONDError condition to check
Example
#include <evo/type.h>
#include <evo/io.h>
using namespace evo;
class ExceptionCustom : public Exception {
};
// Function that returns an error code
Error foo() {
// ...
return ENone;
}
int main() {
try {
Error err = foo();
EVO_THROW_ERR_CHECK(ExceptionCustom, "Error message", EUnknown, (err != ENone));
return 0;
}

◆ INCL_evo_impl_sys_h

#define INCL_evo_impl_sys_h