Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kUtils.h
Go to the documentation of this file.
1
10 #include <kApi/kApiDef.h> //--inclusion order controlled by kApiDef
11
12 #ifndef K_API_UTILS_H
13 #define K_API_UTILS_H
14
15 #include <kApi/Utils/kUtils.x.h>
16
31 kInlineFx(kStatus) kDestroyRef(kObject* object)
32 {
33 kStatus result = kObject_Destroy(*object);
34
35 *object = kNULL;
36
37 return result;
38 }
39
47 kInlineFx(kStatus) kDisposeRef(kObject* object)
48 {
49 kStatus result = kObject_Dispose(*object);
50
51 *object = kNULL;
52
53 return result;
54 }
55
64 kInlineFx(kStatus) kShareRef(kObject* object, kObject source)
65 {
66 if (!kIsNull(source))
67 {
68 kCheck(kObject_Share(source));
69
70 if (!kIsNull(object))
71 {
72 *object = source;
73 }
74 }
75 else
76 {
77 *object = kNULL;
78 }
79
80 return kOK;
81 }
82
94 kInlineFx(kStatus) kReplaceRef(kObject* object, kObject source)
95 {
96 kCheck(kDisposeRef(object));
97
98 kCheck(kShareRef(object, source));
99
100 return kOK;
101 }
102
114 kFx(kStatus) kZeroItems(kType type, void* items, kSize count);
115
128 kFx(kStatus) kCopyItems(kType type, void* dest, const void* src, kSize count);
129
143 kFx(kStatus) kCloneItems(kType type, void* dest, const void* src, kSize count, kAlloc allocator);
144
161 kFx(kStatus) kCloneItemsEx(kType type, void* dest, const void* src, kSize count, kAlloc destAlloc, kAlloc srcAlloc);
162
174 kFx(kStatus) kDisposeItems(kType type, void* items, kSize count);
175
187 kFx(kStatus) kShareItems(kType type, void* items, kSize count);
188
201 kFx(kSize) kMeasureItems(kType type, const void* items, kSize count);
202
214 kFx(kBool) kHasForeignData(kType type, const void* items, kSize count);
215
225 kFx(kStatus) kLoad5(kObject* object, const kChar* fileName, kAlloc allocator);
226
235 kFx(kStatus) kSave5(kObject object, const kChar* fileName);
236
247 kFx(kStatus) kSaveCompressed5(kObject object, const kChar* fileName, kCompressionType algorithm, k32s level);
248
258 kFx(kStatus) kLoad6(kObject* object, const kChar* fileName, kAlloc allocator);
259
268 kFx(kStatus) kSave6(kObject object, const kChar* fileName);
269
280 kFx(kStatus) kSaveCompressed6(kObject object, const kChar* fileName, kCompressionType algorithm, k32s level);
281
292 kFx(kStatus) kMemAlloc(kSize size, void* mem);
293
304 kFx(kStatus) kMemAllocZero(kSize size, void* mem);
305
313 kFx(kStatus) kMemFree(void* mem);
314
322 kFx(kStatus) kMemFreeRef(void* mem);
323
333 kFx(kStatus) kMemSet(void* dest, kByte fill, kSize size);
334
343 kInlineFx(kStatus) kMemZero(void* dest, kSize size)
344 {
345 return kMemSet(dest, 0, size);
346 }
347
357 kFx(kStatus) kMemCopy(void* dest, const void* src, kSize size);
358
368 kFx(kStatus) kMemMove(void* dest, const void* src, kSize size);
369
379 kFx(kStatus) kMemReverseCopy(void* dest, const void* src, kSize size);
380
389 kFx(kStatus) kMemReverse(void* buffer, kSize size);
390
400 kInlineFx(kBool) kMemEquals(const void* a, const void* b, kSize size)
401 {
402 return (memcmp(a, b, size) == 0);
403 }
404
419 kFx(kStatus) kStrCopy(kChar* dest, kSize capacity, const kChar* src);
420
435 kFx(kStatus) kStrCat(kChar* dest, kSize capacity, const kChar* src);
436
446 kFx(kStatus) kStrToLower(kChar* str);
447
456 kFx(kBool) kStrEquals(const kChar* a, const kChar* b);
457
467 kFx(kBool) kStrnEquals(const kChar* a, const kChar* b, kSize maxCount);
468
482 kFx(k32s) kStrCompare(const kChar* a, const kChar* b);
483
498 kFx(k32s) kStrCompareN(const kChar* a, const kChar* b, kSize maxCount);
499
510 kFx(k32s) kStrCompareLower(const kChar* a, const kChar* b);
511
519 kFx(kSize) kStrLength(const kChar* str);
520
529 kFx(const kChar*) kStrFindFirst(const kChar* str, const kChar* subStr);
530
539 kFx(const kChar*) kStrFindLast(const kChar* str, const kChar* subStr);
540
555 kFx(kStatus) kStrPrintf(kChar* dest, kSize capacity, const kChar* format, ...);
556
568 kFx(kStatus) kStrPrintvf(kChar* dest, kSize capacity, const kChar* format, kVarArgList argList);
569
578 kFx(kStatus) kLog(const kChar* message);
579
593 kFx(kStatus) kLogf(const kChar* format, ...);
594
604 kFx(kStatus) kLogvf(const kChar* format, kVarArgList argList);
605
614 kFx(kStatus) kLogBackTrace(kSize skip);
615
622 kFx(k32u) kRandom32u();
623
630 kFx(k64u) kRandom64u();
631
638 kFx(kSize) kRandomSize();
639
648 kFx(kStatus) kRandomBytes(void* data, kSize length);
649
661 kFx(kStatus) kBase64Encode(const void* buffer, kSize size, kString base64String);
662
663 #endif
kUtils::kStrLength
kSize kStrLength(const kChar *str)
Determines the number of kChar units in a characater sequence.
k32u
Represents a 32-bit unsigned integer.
kUtils::kStrPrintvf
kStatus kStrPrintvf(kChar *dest, kSize capacity, const kChar *format, kVarArgList argList)
Variable-argument version of kStrPrintf.
kUtils::kStrCompareN
k32s kStrCompareN(const kChar *a, const kChar *b, kSize maxCount)
Compares one string to another, only up to a maximum number of characters.
kUtils::kMemFree
kStatus kMemFree(void *mem)
Frees a block of memory that was allocated using kMemAlloc or kMemAllocZero.
k64u
Represents a 64-bit unsigned integer.
kUtils::kLoad5
kStatus kLoad5(kObject *object, const kChar *fileName, kAlloc allocator)
Loads an object from file using kDat-5 serialization.
kUtils::kStrCat
kStatus kStrCat(kChar *dest, kSize capacity, const kChar *src)
Appends characters from source to destination.
kPointer::kIsNull
#define kIsNull(POINTER)
Tests for equality with null pointer.
Definition: kApiDef.h:341
kUtils::kMemMove
kStatus kMemMove(void *dest, const void *src, kSize size)
Copies memory from a source buffer to a potentially-overlapping destination.
kUtils::kDisposeItems
kStatus kDisposeItems(kType type, void *items, kSize count)
Disposes a generic array of items.
kUtils::kStrCompareLower
k32s kStrCompareLower(const kChar *a, const kChar *b)
Performs a case-insenstive comparison of two strings.
kUtils::kLogvf
kStatus kLogvf(const kChar *format, kVarArgList argList)
Variable-argument version of kLogf.
kUtils::kStrFindLast
const kChar * kStrFindLast(const kChar *str, const kChar *subStr)
Finds the last occurrence of a character sequence.
kUtils::kStrEquals
kBool kStrEquals(const kChar *a, const kChar *b)
Tests a pair of character sequences for equality.
kUtils::kSave5
kStatus kSave5(kObject object, const kChar *fileName)
Saves an object to file using kDat-5 serialization.
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kObject::kObject_Share
kStatus kObject_Share(kObject object)
Increments the reference count associated with this object.
Definition: kObject.h:119
kUtils::kMemAlloc
kStatus kMemAlloc(kSize size, void *mem)
Allocates a block of memory from the application heap.
kUtils::kShareRef
kStatus kShareRef(kObject *object, kObject source)
Shares an object and sets a handle to refer to the shared object.
Definition: kUtils.h:64
kCheck
#define kCheck(EXPRESSION)
Executes a return statement if the given expression is not kOK.
Definition: kApiDef.h:561
kUtils::kStrCompare
k32s kStrCompare(const kChar *a, const kChar *b)
Compares one string to another.
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kUtils::kStrToLower
kStatus kStrToLower(kChar *str)
Converts characters in the given sequence to lower case.
kUtils::kMemEquals
kBool kMemEquals(const void *a, const void *b, kSize size)
Compares one memory buffer with another.
Definition: kUtils.h:400
kUtils::kMemCopy
kStatus kMemCopy(void *dest, const void *src, kSize size)
Copies memory from a source buffer to a non-overlapping destination.
kChar
Represents a single unit (byte) in a UTF-8 character.
kUtils::kRandomBytes
kStatus kRandomBytes(void *data, kSize length)
Generates a random array of bytes.
kByte
Represents a byte on the current platform.
kUtils::kMeasureItems
kSize kMeasureItems(kType type, const void *items, kSize count)
Calculates the total size, in bytes, of a generic array of items.
kUtils::kDisposeRef
kStatus kDisposeRef(kObject *object)
Disposes an object and resets the object handle to kNULL.
Definition: kUtils.h:47
kUtils::kMemFreeRef
kStatus kMemFreeRef(void *mem)
Frees a block of memory that was allocated using kMemAlloc or kMemAllocZero and resets the memory poi...
kUtils::kRandom32u
k32u kRandom32u()
Generates a random 32-bit number.
kUtils::kCloneItems
kStatus kCloneItems(kType type, void *dest, const void *src, kSize count, kAlloc allocator)
Performs a deep copy of a generic array of items.
kUtils::kDestroyRef
kStatus kDestroyRef(kObject *object)
Destroys an object and resets the object handle to kNULL.
Definition: kUtils.h:31
kUtils::kLogf
kStatus kLogf(const kChar *format,...)
Formats and writes a message to log handlers (if registered).
kUtils::kMemZero
kStatus kMemZero(void *dest, kSize size)
Sets a block of memory to zero.
Definition: kUtils.h:343
kCompressionType
Type of compression algorithm.
kUtils::kSave6
kStatus kSave6(kObject object, const kChar *fileName)
Saves an object to file using kDat-6 serialization.
kUtils::kLoad6
kStatus kLoad6(kObject *object, const kChar *fileName, kAlloc allocator)
Loads an object from file using kDat-6 serialization.
kUtils::kMemAllocZero
kStatus kMemAllocZero(kSize size, void *mem)
Allocates and zero-initializes block of memory from the application heap.
kUtils::kSaveCompressed5
kStatus kSaveCompressed5(kObject object, const kChar *fileName, kCompressionType algorithm, k32s level)
Saves an object to file using kDat-5 serialization and compression.
kApiDef.h
Core Zen type declarations.
k32s
Represents a 32-bit signed integer.
kUtils::kLog
kStatus kLog(const kChar *message)
Writes a message to log handlers (if registered).
kUtils::kMemReverseCopy
kStatus kMemReverseCopy(void *dest, const void *src, kSize size)
Copies memory in reverse from a source buffer to a non-overlapping destination.
kUtils::kRandom64u
k64u kRandom64u()
Generates a random 64-bit number.
kUtils::kStrPrintf
kStatus kStrPrintf(kChar *dest, kSize capacity, const kChar *format,...)
Formats a string using printf-style arguments.
kObject::kObject_Destroy
kStatus kObject_Destroy(kObject object)
Destroys the object.
Definition: kObject.h:165
kUtils::kLogBackTrace
kStatus kLogBackTrace(kSize skip)
Writes a stack backtrace to the logging handler (if registered).
kUtils::kStrCopy
kStatus kStrCopy(kChar *dest, kSize capacity, const kChar *src)
Copies characters from source to destination.
kString
Represents a character string.
kUtils::kCloneItemsEx
kStatus kCloneItemsEx(kType type, void *dest, const void *src, kSize count, kAlloc destAlloc, kAlloc srcAlloc)
Performs a deep copy of a generic array of items.
kUtils::kCopyItems
kStatus kCopyItems(kType type, void *dest, const void *src, kSize count)
Performs a shallow copy of a generic array of items.
kType
Represents metadata about a type (class, interface, or value).
kObject::kObject_Dispose
kStatus kObject_Dispose(kObject object)
Destroys the object and any aggregated child elements.
Definition: kObject.h:193
kUtils::kSaveCompressed6
kStatus kSaveCompressed6(kObject object, const kChar *fileName, kCompressionType algorithm, k32s level)
Saves an object to file using kDat-6 serialization and compression.
kUtils::kRandomSize
kSize kRandomSize()
Generates a random number of type kSize.
kObject
Root of all Zen classes.
kStatus::kOK
#define kOK
Operation successful.
Definition: kApiDef.h:515
kStatus
Represents an error code.
kNULL
#define kNULL
Null pointer.
Definition: kApiDef.h:269
kUtils::kMemReverse
kStatus kMemReverse(void *buffer, kSize size)
Reverse the order of bytes in a buffer.
kUtils::kShareItems
kStatus kShareItems(kType type, void *items, kSize count)
Increments the reference count of a generic array of items.
kUtils::kStrFindFirst
const kChar * kStrFindFirst(const kChar *str, const kChar *subStr)
Finds the first occurrence of a character sequence.
kBool
Represents a boolean value.
kUtils::kStrnEquals
kBool kStrnEquals(const kChar *a, const kChar *b, kSize maxCount)
Tests a pair of character sequences for equality, up to a maximum number of characters.
kUtils::kReplaceRef
kStatus kReplaceRef(kObject *object, kObject source)
Replaces a reference to existing object with a new object.
Definition: kUtils.h:94
kUtils::kZeroItems
kStatus kZeroItems(kType type, void *items, kSize count)
Zeros the memory associated with a generic array of items.
kUtils::kMemSet
kStatus kMemSet(void *dest, kByte fill, kSize size)
Sets a block of memory to the given byte value.
kUtils::kHasForeignData
kBool kHasForeignData(kType type, const void *items, kSize count)
Reports whether any objects in the specified array reference memory in a foreign address space...