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
156 kFx(kStatus) kDisposeItems(kType type, void* items, kSize count);
157
169 kFx(kStatus) kShareItems(kType type, void* items, kSize count);
170
183 kFx(kSize) kMeasureItems(kType type, const void* items, kSize count);
184
194 kFx(kStatus) kLoad5(kObject* object, const kChar* fileName, kAlloc allocator);
195
204 kFx(kStatus) kSave5(kObject object, const kChar* fileName);
205
215 kFx(kStatus) kLoad6(kObject* object, const kChar* fileName, kAlloc allocator);
216
225 kFx(kStatus) kSave6(kObject object, const kChar* fileName);
226
237 kFx(kStatus) kMemAlloc(kSize size, void* mem);
238
249 kFx(kStatus) kMemAllocZero(kSize size, void* mem);
250
258 kFx(kStatus) kMemFree(void* mem);
259
267 kFx(kStatus) kMemFreeRef(void* mem);
268
278 kFx(kStatus) kMemSet(void* dest, kByte fill, kSize size);
279
288 kInlineFx(kStatus) kMemZero(void* dest, kSize size)
289 {
290 return kMemSet(dest, 0, size);
291 }
292
302 kFx(kStatus) kMemCopy(void* dest, const void* src, kSize size);
303
313 kFx(kStatus) kMemMove(void* dest, const void* src, kSize size);
314
324 kFx(kStatus) kMemReverseCopy(void* dest, const void* src, kSize size);
325
334 kFx(kStatus) kMemReverse(void* buffer, kSize size);
335
345 kInlineFx(kBool) kMemEquals(const void* a, const void* b, kSize size)
346 {
347 return (memcmp(a, b, size) == 0);
348 }
349
364 kFx(kStatus) kStrCopy(kChar* dest, kSize capacity, const kChar* src);
365
380 kFx(kStatus) kStrCat(kChar* dest, kSize capacity, const kChar* src);
381
391 kFx(kStatus) kStrToLower(kChar* str);
392
401 kFx(kBool) kStrEquals(const kChar* a, const kChar* b);
402
412 kFx(kBool) kStrnEquals(const kChar* a, const kChar* b, kSize maxCount);
413
427 kFx(k32s) kStrCompare(const kChar* a, const kChar* b);
428
443 kFx(k32s) kStrCompareN(const kChar* a, const kChar* b, kSize maxCount);
444
455 kFx(k32s) kStrCompareLower(const kChar* a, const kChar* b);
456
464 kFx(kSize) kStrLength(const kChar* str);
465
474 kFx(const kChar*) kStrFindFirst(const kChar* str, const kChar* subStr);
475
484 kFx(const kChar*) kStrFindLast(const kChar* str, const kChar* subStr);
485
500 kFx(kStatus) kStrPrintf(kChar* dest, kSize capacity, const kChar* format, ...);
501
513 kFx(kStatus) kStrPrintvf(kChar* dest, kSize capacity, const kChar* format, kVarArgList argList);
514
523 kFx(kStatus) kLog(const kChar* message);
524
538 kFx(kStatus) kLogf(const kChar* format, ...);
539
549 kFx(kStatus) kLogvf(const kChar* format, kVarArgList argList);
550
559 kFx(kStatus) kLogBackTrace(kSize skip);
560
567 kFx(k32u) kRandom32u();
568
575 kFx(k64u) kRandom64u();
576
583 kFx(kSize) kRandomSize();
584
593 kFx(kStatus) kRandomBytes(void* data, kSize length);
594
606 kFx(kStatus) kBase64Encode(const void* buffer, kSize size, kString base64String);
607
608 #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:339
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:559
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:345
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:288
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.
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::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::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:513
kStatus
Represents an error code.
kNULL
#define kNULL
Null pointer.
Definition: kApiDef.h:267
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.