Zen API
 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 
32 {
33  kStatus result = kObject_Destroy(*object);
34 
35  *object = kNULL;
36 
37  return result;
38 }
39 
48 {
49  kStatus result = kObject_Dispose(*object);
50 
51  *object = kNULL;
52 
53  return result;
54 }
55 
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 
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 kInlineFx(kStatus) kCopyItems(kType type, void* dest, const void* src, kSize count)
129 {
130  return xkCopyItems(type, dest, src, count);
131 }
132 
148 #if defined (K_CPP)
149 kInlineFx(kStatus) kCopyItems(kType type, kAlloc destAlloc, void* dest, kAlloc srcAlloc, const void* src, kSize count, kObject context)
150 {
151  return xkCopyItemsEx(type, destAlloc, dest, srcAlloc, src, count, context);
152 }
153 #endif
154 
168 kInlineFx(kStatus) kCloneItems(kType type, void* dest, const void* src, kSize count, kAlloc allocator)
169 {
170  return xkCloneItems(type, dest, src, count, allocator);
171 }
172 
192 #if defined (K_CPP)
193 kInlineFx(kStatus) kCloneItems(kType type, kAlloc destAlloc, void* dest, kAlloc srcAlloc, const void* src, kSize count, kObject context, kAlloc destObjectAlloc, kAlloc destValueAlloc)
194 {
195  return xkCloneItemsEx(type, destAlloc, dest, srcAlloc, src, count, context, destObjectAlloc, destValueAlloc);
196 }
197 #endif
198 
210 kFx(kStatus) kDisposeItems(kType type, void* items, kSize count);
211 
223 kFx(kStatus) kShareItems(kType type, void* items, kSize count);
224 
237 kFx(kSize) kMeasureItems(kType type, const void* items, kSize count);
238 
250 kFx(kBool) kHasSharedItems(kType type, const void* items, kSize count);
251 
263 kFx(kBool) kEnumerateAllocTraits(kType type, const void* items, kSize count);
264 
274 kFx(kStatus) kLoad5(kObject* object, const kChar* fileName, kAlloc allocator);
275 
284 kFx(kStatus) kSave5(kObject object, const kChar* fileName);
285 
296 kFx(kStatus) kSaveCompressed5(kObject object, const kChar* fileName, kCompressionType algorithm, k32s level);
297 
307 kFx(kStatus) kLoad6(kObject* object, const kChar* fileName, kAlloc allocator);
308 
317 kFx(kStatus) kSave6(kObject object, const kChar* fileName);
318 
329 kFx(kStatus) kSaveCompressed6(kObject object, const kChar* fileName, kCompressionType algorithm, k32s level);
330 
341 kFx(kStatus) kMemAlloc(kSize size, void* mem);
342 
353 kFx(kStatus) kMemAllocZero(kSize size, void* mem);
354 
362 kFx(kStatus) kMemFree(void* mem);
363 
371 kFx(kStatus) kMemFreeRef(void* mem);
372 
382 kFx(kStatus) kMemSet(void* dest, kByte fill, kSize size);
383 
392 kInlineFx(kStatus) kMemZero(void* dest, kSize size)
393 {
394  return kMemSet(dest, 0, size);
395 }
396 
406 kFx(kStatus) kMemCopy(void* dest, const void* src, kSize size);
407 
417 kFx(kStatus) kMemMove(void* dest, const void* src, kSize size);
418 
428 kFx(kStatus) kMemReverseCopy(void* dest, const void* src, kSize size);
429 
438 kFx(kStatus) kMemReverse(void* buffer, kSize size);
439 
449 kInlineFx(kBool) kMemEquals(const void* a, const void* b, kSize size)
450 {
451  return (memcmp(a, b, size) == 0);
452 }
453 
468 kFx(kStatus) kStrCopy(kChar* dest, kSize capacity, const kChar* src);
469 
484 kFx(kStatus) kStrCat(kChar* dest, kSize capacity, const kChar* src);
485 
495 kFx(kStatus) kStrToLower(kChar* str);
496 
505 kFx(kBool) kStrEquals(const kChar* a, const kChar* b);
506 
516 kFx(kBool) kStrnEquals(const kChar* a, const kChar* b, kSize maxCount);
517 
531 kFx(k32s) kStrCompare(const kChar* a, const kChar* b);
532 
547 kFx(k32s) kStrCompareN(const kChar* a, const kChar* b, kSize maxCount);
548 
559 kFx(k32s) kStrCompareLower(const kChar* a, const kChar* b);
560 
568 kFx(kSize) kStrLength(const kChar* str);
569 
578 kFx(const kChar*) kStrFindFirst(const kChar* str, const kChar* subStr);
579 
588 kFx(const kChar*) kStrFindLast(const kChar* str, const kChar* subStr);
589 
604 kFx(kStatus) kStrPrintf(kChar* dest, kSize capacity, const kChar* format, ...);
605 
617 kFx(kStatus) kStrPrintvf(kChar* dest, kSize capacity, const kChar* format, kVarArgList argList);
618 
628 kFx(kStatus) kLogvf(const kChar* format, kVarArgList argList);
629 
641 #if defined(K_CPP)
642 kInlineFx(kStatus) kLogvf(kLogOption options, const kChar* source, const kChar* format, kVarArgList argList)
643 {
644  return xkLogvf(options, source, format, argList);
645 }
646 #endif
647 
661 kFx(kStatus) kLogf(const kChar* format, ...);
662 
678 #if defined(K_CPP)
679 kInlineFx(kStatus) kLogf(kLogOption options, const kChar* source, const kChar* format, ...)
680 {
681  kVarArgList argList;
682  kStatus status;
683 
684  kVarArgList_Start(argList, format);
685  {
686  status = kLogvf(options, source, format, argList);
687  }
688  kVarArgList_End(argList);
689 
690  return status;
691 }
692 #endif
693 
702 kFx(kStatus) kLog(const kChar* message);
703 
714 #if defined(K_CPP)
715 kInlineFx(kStatus) kLog(kLogOption options, const kChar* source, const kChar* message)
716 {
717  return kLogf(options, source, "%s", message);
718 }
719 #endif
720 
729 kFx(kStatus) kLogBackTrace(kSize skip);
730 
741 #if defined(K_CPP)
742 kInlineFx(kStatus) kLogBackTrace(kLogOption options, const kChar* source, kSize skip)
743 {
744  return xkLogBackTrace(options, source, skip);
745 }
746 #endif
747 
754 kFx(k32u) kRandom32u();
755 
762 kFx(k64u) kRandom64u();
763 
770 kFx(kSize) kRandomSize();
771 
780 kFx(kStatus) kRandomBytes(void* data, kSize length);
781 
793 kFx(kStatus) kBase64Encode(const void* buffer, kSize size, kString base64String);
794 
795 #endif
kSize kStrLength(const kChar *str)
Determines the number of kChar units in a characater sequence.
Represents a 32-bit unsigned integer.
kStatus kStrPrintvf(kChar *dest, kSize capacity, const kChar *format, kVarArgList argList)
Variable-argument version of kStrPrintf.
k32s kStrCompareN(const kChar *a, const kChar *b, kSize maxCount)
Compares one string to another, only up to a maximum number of characters.
kStatus kMemFree(void *mem)
Frees a block of memory that was allocated using kMemAlloc or kMemAllocZero.
Represents a 64-bit unsigned integer.
kStatus kLoad5(kObject *object, const kChar *fileName, kAlloc allocator)
Loads an object from file using kDat-5 serialization.
kStatus kStrCat(kChar *dest, kSize capacity, const kChar *src)
Appends characters from source to destination.
#define kIsNull(POINTER)
Tests for equality with null pointer.
Definition: kApiDef.h:341
kStatus kMemMove(void *dest, const void *src, kSize size)
Copies memory from a source buffer to a potentially-overlapping destination.
kStatus kDisposeItems(kType type, void *items, kSize count)
Disposes a generic array of items.
k32s kStrCompareLower(const kChar *a, const kChar *b)
Performs a case-insenstive comparison of two strings.
kStatus kLogvf(const kChar *format, kVarArgList argList)
Variable-argument version of kLogf.
const kChar * kStrFindLast(const kChar *str, const kChar *subStr)
Finds the last occurrence of a character sequence.
kBool kStrEquals(const kChar *a, const kChar *b)
Tests a pair of character sequences for equality.
kStatus kSave5(kObject object, const kChar *fileName)
Saves an object to file using kDat-5 serialization.
Represents an unsigned integer that can store a pointer address.
Abstract base class for memory allocator types.
kStatus kObject_Share(kObject object)
Increments the reference count associated with this object.
Definition: kObject.h:162
kStatus kMemAlloc(kSize size, void *mem)
Allocates a block of memory from the application heap.
kStatus kShareRef(kObject *object, kObject source)
Shares an object and sets a handle to refer to the shared object.
Definition: kUtils.h:64
#define kCheck(EXPRESSION)
Executes a return statement if the given expression is not kOK.
Definition: kApiDef.h:561
k32s kStrCompare(const kChar *a, const kChar *b)
Compares one string to another.
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kStatus kStrToLower(kChar *str)
Converts characters in the given sequence to lower case.
kBool kMemEquals(const void *a, const void *b, kSize size)
Compares one memory buffer with another.
Definition: kUtils.h:449
kStatus kMemCopy(void *dest, const void *src, kSize size)
Copies memory from a source buffer to a non-overlapping destination.
Represents a single unit (byte) in a UTF-8 character.
kStatus kRandomBytes(void *data, kSize length)
Generates a random array of bytes.
Represents a byte on the current platform.
kSize kMeasureItems(kType type, const void *items, kSize count)
Calculates the total size, in bytes, of a generic array of items.
kStatus kDisposeRef(kObject *object)
Disposes an object and resets the object handle to kNULL.
Definition: kUtils.h:47
kStatus kMemFreeRef(void *mem)
Frees a block of memory that was allocated using kMemAlloc or kMemAllocZero and resets the memory poi...
k32u kRandom32u()
Generates a random 32-bit number.
kStatus kCloneItems(kType type, void *dest, const void *src, kSize count, kAlloc allocator)
Performs a deep copy of a generic array of items.
Definition: kUtils.h:168
kStatus kDestroyRef(kObject *object)
Destroys an object and resets the object handle to kNULL.
Definition: kUtils.h:31
kStatus kLogf(const kChar *format,...)
Formats and writes a message to log handlers (if registered).
kStatus kMemZero(void *dest, kSize size)
Sets a block of memory to zero.
Definition: kUtils.h:392
Type of compression algorithm.
kStatus kSave6(kObject object, const kChar *fileName)
Saves an object to file using kDat-6 serialization.
kBool kHasSharedItems(kType type, const void *items, kSize count)
Determines whether a list of items contains any shared objects.
kStatus kLoad6(kObject *object, const kChar *fileName, kAlloc allocator)
Loads an object from file using kDat-6 serialization.
kStatus kMemAllocZero(kSize size, void *mem)
Allocates and zero-initializes block of memory from the application heap.
kStatus kSaveCompressed5(kObject object, const kChar *fileName, kCompressionType algorithm, k32s level)
Saves an object to file using kDat-5 serialization and compression.
Core Zen type declarations.
Represents a 32-bit signed integer.
kStatus kLog(const kChar *message)
Writes a message to log handlers (if registered).
kStatus kMemReverseCopy(void *dest, const void *src, kSize size)
Copies memory in reverse from a source buffer to a non-overlapping destination.
k64u kRandom64u()
Generates a random 64-bit number.
kStatus kStrPrintf(kChar *dest, kSize capacity, const kChar *format,...)
Formats a string using printf-style arguments.
kStatus kObject_Destroy(kObject object)
Destroys the object.
Definition: kObject.h:208
kStatus kLogBackTrace(kSize skip)
Writes a stack backtrace to the logging handler (if registered).
kStatus kStrCopy(kChar *dest, kSize capacity, const kChar *src)
Copies characters from source to destination.
Represents a character string.
kStatus kCopyItems(kType type, void *dest, const void *src, kSize count)
Performs a shallow copy of a generic array of items.
Definition: kUtils.h:128
Represents metadata about a type (class, interface, or value).
kStatus kObject_Dispose(kObject object)
Destroys the object and any aggregated child elements.
Definition: kObject.h:236
kStatus kSaveCompressed6(kObject object, const kChar *fileName, kCompressionType algorithm, k32s level)
Saves an object to file using kDat-6 serialization and compression.
kSize kRandomSize()
Generates a random number of type kSize.
Represents options associated with a log entry.
Root of all Zen classes.
#define kOK
Operation successful.
Definition: kApiDef.h:515
Represents an error code.
#define kNULL
Null pointer.
Definition: kApiDef.h:269
kStatus kMemReverse(void *buffer, kSize size)
Reverse the order of bytes in a buffer.
kStatus kShareItems(kType type, void *items, kSize count)
Increments the reference count of a generic array of items.
kBool kEnumerateAllocTraits(kType type, const void *items, kSize count)
Gets the bitset of allocator traits associated with objects in the specified array.
const kChar * kStrFindFirst(const kChar *str, const kChar *subStr)
Finds the first occurrence of a character sequence.
Represents a boolean value.
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.
kStatus kReplaceRef(kObject *object, kObject source)
Replaces a reference to existing object with a new object.
Definition: kUtils.h:94
kStatus kZeroItems(kType type, void *items, kSize count)
Zeros the memory associated with a generic array of items.
kStatus kMemSet(void *dest, kByte fill, kSize size)
Sets a block of memory to the given byte value.