the_Foundation 1.0
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
defs.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "garbage.h"
#include "argcount.h"
#include <assert.h>

Data Structures

struct  iBoolv
 

Macros

#define iPublic
 
#define iBeginPublic
 
#define iEndPublic
 
#define iLocalDef   static inline
 
#define iFalse   false
 
#define iTrue   true
 
#define iInvalidPos   ((size_t) -1)
 
#define iInvalidSize   ((size_t) -1)
 
#define iBit(n1_to_32)   (1U << (n1_to_32 - 1))
 
#define iBit64(n1_to_64)   (1ULL << (n1_to_64 - 1))
 
#define iMin(a, b)   ((a) < (b) ? (a) : (b))
 
#define iMax(a, b)   ((a) > (b) ? (a) : (b))
 
#define iAbs(a)   ((a) > 0 ? (a) : -(a))
 
#define iClamp(i, low, high)   ((i) < (low) ? (low) : (i) > (high) ? (high) : (i))
 
#define iCmp(a, b)   ((a) > (b) ? 1 : (a) < (b) ? -1 : 0)
 
#define iElemCount(ar)   (sizeof(ar) / sizeof((ar)[0]))
 
#define iSwap(typeName, a, b)   { typeName tmp_Swap_ = (a); (a) = (b); (b) = tmp_Swap_; }
 
#define iChangeFlags(var, flags, doSet)   {if (doSet) { (var) |= (flags); } else { (var) &= ~(flags); }}
 
#define iUnusedMany_(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, ...)
 
#define iUnused(...)   iUnusedMany_(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
 
#define iZap(var)   memset(&(var), 0, sizeof(var));
 
#define iMalloc(typeName)   ((i##typeName *) malloc(sizeof(i##typeName)))
 
#define iZapMalloc(typeName)   ((i##typeName *) calloc(sizeof(i##typeName), 1))
 
#define iConstCast(type, ptr)   ((type) (intptr_t) (ptr))
 
#define iFunctionCast(type, ptr)   ((type) (ptr))
 
#define iDeclareType(typeName)   typedef struct Impl_##typeName i##typeName;
 
#define iDeclareTypeConstruction(typeName)
 
#define iDeclareTypeConstructionArgs(typeName, ...)
 
#define iDefineTypeConstruction(typeName)
 
#define iDefineStaticTypeConstruction(typeName)
 
#define iDefineTypeConstructionArgs(typeName, newArgs, ...)
 
#define iDeclareTypeSerialization(typeName)
 
#define iDeclareIterator_(iterType, typeName, container)
 
#define iDeclareIterator(typeName, container)    iDeclareIterator_(Iterator, typeName, container)
 
#define iDeclareConstIterator(typeName, container)    iDeclareIterator_(ConstIterator, typeName, container)
 
#define iIterate(typeName, iterType, iterName, container)
 
#define iForIndices(iterName, container)    for (size_t iterName = 0; iterName < iElemCount(container); ++iterName)
 
#define iForEach(typeName, iterName, container)    iIterate(typeName, Iterator, iterName, container)
 
#define iReverseForEach(typeName, iterName, container)    iIterate(typeName, ReverseIterator, iterName, container)
 
#define iConstForEach(typeName, iterName, container)    iIterate(typeName, ConstIterator, iterName, container)
 
#define iReverseConstForEach(typeName, iterName, container)    iIterate(typeName, ReverseConstIterator, iterName, container)
 
#define iForVarArgs(type, var, body)
 
#define iAssert(cond)   assert(cond)
 
#define iDebugOnly(...)
 
#define iDebug(...)
 
#define iWarning(...)
 

Typedefs

typedef bool iBool
 
typedef void iAny
 
typedef void iAnyObject
 
typedef void(* iDeinitFunc) (iAny *)
 
typedef void(* iDeleteFunc) (iAny *)
 

Functions

void init_Foundation (void)
 
void deinit_Foundation (void)
 
iBool isInitialized_Foundation (void)
 
void setLocale_Foundation (void)
 
void printMessage_Foundation (FILE *, const char *format,...)
 
uint32_t iCrc32 (const char *data, size_t size)
 
void iMd5Hash (const void *data, size_t size, uint8_t md5_out[16])
 

Detailed Description

General definitions.

Authors
Copyright (c) 2017 Jaakko Keränen jaakk.nosp@m.o.ke.nosp@m.ranen.nosp@m.@iki.nosp@m..fi
License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ iDeclareIterator_

#define iDeclareIterator_ (   iterType,
  typeName,
  container 
)
Value:
typedef struct iterType##Impl_##typeName i##typeName##iterType; \
typedef struct iterType##Impl_##typeName i##typeName##Reverse##iterType; \
void init_##typeName##iterType(i##typeName##iterType *, container); \
void next_##typeName##iterType(i##typeName##iterType *); \
void init_##typeName##Reverse##iterType(i##typeName##Reverse##iterType *, container); \
void next_##typeName##Reverse##iterType(i##typeName##Reverse##iterType *);

◆ iDeclareTypeConstruction

#define iDeclareTypeConstruction (   typeName)
Value:
i##typeName *new_##typeName(void); \
void delete_##typeName(i##typeName *); \
iLocalDef i##typeName *collect_##typeName(i##typeName *d) { \
return iCollectDel(d, delete_##typeName); \
} \
iLocalDef i##typeName *collectNew_##typeName(void) { \
return collect_##typeName(new_##typeName()); \
} \
void init_##typeName(i##typeName *); \
void deinit_##typeName(i##typeName *);

◆ iDeclareTypeConstructionArgs

#define iDeclareTypeConstructionArgs (   typeName,
  ... 
)
Value:
i##typeName *new_##typeName(__VA_ARGS__); \
void delete_##typeName(i##typeName *); \
iLocalDef i##typeName *collect_##typeName(i##typeName *d) { \
return iCollectDel(d, delete_##typeName); \
} \
void init_##typeName(i##typeName *, __VA_ARGS__); \
void deinit_##typeName(i##typeName *);

◆ iDeclareTypeSerialization

#define iDeclareTypeSerialization (   typeName)
Value:
void serialize_##typeName(const i##typeName *, iStream *); \
void deserialize_##typeName(i##typeName *, iStream *);

◆ iDefineStaticTypeConstruction

#define iDefineStaticTypeConstruction (   typeName)
Value:
static i##typeName *new_##typeName##_(void) { \
i##typeName *d = iMalloc(typeName); \
init_##typeName##_(d); \
return d; \
} \
static void delete_##typeName##_(i##typeName *d) { \
deinit_##typeName##_(d); \
free(d); \
}

◆ iDefineTypeConstruction

#define iDefineTypeConstruction (   typeName)
Value:
i##typeName *new_##typeName(void) { \
i##typeName *d = iMalloc(typeName); \
init_##typeName(d); \
return d; \
} \
void delete_##typeName(i##typeName *d) { \
if (d) { \
deinit_##typeName(d); \
free(d); \
} \
}

◆ iDefineTypeConstructionArgs

#define iDefineTypeConstructionArgs (   typeName,
  newArgs,
  ... 
)
Value:
i##typeName *new_##typeName newArgs { \
i##typeName *d = iMalloc(typeName); \
init_##typeName(d, __VA_ARGS__); \
return d; \
} \
void delete_##typeName(i##typeName *d) { \
if (d) { \
deinit_##typeName(d); \
free(d); \
} \
}

◆ iForVarArgs

#define iForVarArgs (   type,
  var,
  body 
)
Value:
{ \
{ body; } \
va_list iVarArgs_; \
for (va_start(iVarArgs_, var);;) { \
var = va_arg(iVarArgs_, type); \
if (!var) break; \
{ body; } \
} \
va_end(iVarArgs_); }

◆ iIterate

#define iIterate (   typeName,
  iterType,
  iterName,
  container 
)
Value:
i##typeName##iterType iterName; \
for (init_##typeName##iterType(&iterName, container); \
iterName.value; \
next_##typeName##iterType(&iterName))

◆ iUnusedMany_

#define iUnusedMany_ (   _0,
  _1,
  _2,
  _3,
  _4,
  _5,
  _6,
  _7,
  _8,
  _9,
  ... 
)
Value:
((void)(_0), (void)(_1), (void)(_2), (void)(_3), (void)(_4), \
(void)(_5), (void)(_6), (void)(_7), (void)(_8), (void)(_9))