Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.89 KB | None | 0 0
  1. //
  2. //  LiteFoundation.h
  3. //  Lite Foundation
  4. //
  5. //  Copyright (c) 2010 by Sidney Just
  6. //  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  7. //  documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  8. //  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
  9. //  and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  10. //  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11. //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  12. //  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  13. //  PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  14. //  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15. //  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. //
  17.  
  18. /*! \mainpage Lite Foundation framework reference
  19.  *
  20.  *
  21.  * \section intro_sec Introduction
  22.  * This is the reference for the Lite framework library. The Lite Foundation framework is a library of common used functions and types. <br>
  23.  * It is written in plain C and should run on every machine that provides the standard C library.
  24.  * <br>
  25.  *
  26.  * \section usage_sec Usage
  27.  * 1) Include the LiteFoundation.h header<br>
  28.  * 2) Define your target via the _TARGET_XX_XX defines inside the LFAPI.h header (read the comments inside the header for more informations)<br>
  29.  * 3) No third step ;)
  30.  * <br>
  31.  *
  32.  * \section changes_sec Change log
  33.  * <b>Version 0.4:</b><br />
  34.  * * Added the LFNotificationCenterRef object. <br />
  35.  * * Added the LFNotificationRef object. <br />
  36.  * * Added functions to read and write LFDataRef objects from and to files. <br />
  37.  * * Fixed a bug with LFDictionaryRef and the LFCoder. <br />
  38.  * <br />
  39.  * <b>Version 0.3.5:</b><br />
  40.  * * Added the LFRunLoopObserverRef object. <br />
  41.  * * Added the LFAutorelease() function. <br />
  42.  * * Added functions that create autoreleased objects <br />
  43.  * * Moved the LFTimerRef fire logic from the run loop to the LFTimerRef object. <br />
  44.  * * Fixed a bug with LFRunLoopRunUntilDate() function <br />
  45.  * <br />
  46.  * <b>Version 0.3.4:</b><br />
  47.  * * Added the LFDateRef object. <br />
  48.  * * Added the LFRunLoopRef object. <br />
  49.  * * Added the LFTimerRef object. <br />
  50.  * * Added the LFDescription() function. <br />
  51.  * <br />
  52.  * <b>Version 0.3:</b><br />
  53.  * * Added serialization for LFDictionaryRef. <br />
  54.  * * Added functions to use a CString key as key for an LFDictionaryRef (LFDictionaryAddCKeyAndValue() and LFDictionaryValueForCKey())
  55.  * * Added a function to compare two Lite Foundation object. It doesn't only compare their pointers but also their contents (LFTypeIsEqual()) <br />
  56.  * * Added a function for generating an LFDataRef out of a subset of another LFDataRef (LFDataGetDataInRange()) <br />
  57.  * * Added two functions to the LFNumberRef that allows you to store and receive pointer addresses (LFNumberCreateWithPointer() and LFNumberPointerValue()) <br />
  58.  * * Added zombies to make crashes because of object over-releasing easier (LFEnableZombies()) <br />
  59.  * * Changed the LFDictionaryRef so that it now checks the content of an key instead of just checking the pointer. <br />
  60.  * <br />
  61.  * <b>Version 0.2:</b><br />
  62.  * * Added the LFDictionaryRef object for Lite-C <br />
  63.  * * Added better version handling <br />
  64.  * * Added a few functions for the LFStringRef to make it easier to work with pathes and manipulate string objects. <br />
  65.  * * Changed the LFArrayHasObject() function name to LFArrayContainsObject(). However, LFArrayHasObject() is still available als macro that calls LFArrayContainsObject. <br />
  66.  * * Changed the LFAutoreleasePoolRef behavior. It doesn't change the retain count anymore which results in instant deallocation if the pool is the only one who holds an reference to the object. This can reduce your memory footprint but shouldn't change your application flow. <br />
  67.  * * Changed the LFArrayRef behavior. When removing all objects it will also reduce the memory footprint of the array instead of just setting the count back to 0. <br />
  68.  * <br />
  69.  * <b>Version 0.1:</b><br />
  70.  * * Initial release.<br />
  71.  *
  72.  * <br>
  73.  */
  74.  
  75. #ifndef _LITEFOUNDATION_H_
  76. #define _LITEFOUNDATION_H_
  77.  
  78. #include "LFAPI.h"
  79.  
  80. // --------------------------------------------------------------------------
  81. // Defines
  82. // --------------------------------------------------------------------------
  83.  
  84. #define LFVersionMajor 0
  85. #define LFVersionMinor 4
  86. #define LFVersionPatch 0
  87.  
  88. #define LFVersionCreate(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
  89.  
  90. // --------------------------------------------------------------------------
  91. // Includes
  92. // The default Lite Foundation includes
  93. // --------------------------------------------------------------------------
  94. #include "LFAllocator.h"
  95. #include "LFType.h"
  96. #include "LFCoder.h"
  97. #include "LFAutoreleasePool.h"
  98. #include "LFData.h"
  99. #include "LFDate.h"
  100. #include "LFDictionary.h"
  101. #include "LFArray.h"
  102. #include "LFValue.h"
  103. #include "LFNumber.h"
  104. #include "LFString.h"
  105. #include "LFRunLoop.h"
  106. #include "LFTimer.h"
  107. #include "LFRunLoopObserver.h"
  108. #include "LFNotification.h"
  109. #include "LFNotificationCenter.h"
  110.  
  111. #ifdef _TARGET_LANG_LC_
  112.     #include "LFAllocator.c"
  113.     #include "LFType.c"
  114.     #include "LFCoder.c"
  115.     #include "LFAutoreleasePool.c"
  116.     #include "LFData.c"
  117.     #include "LFDate.c"
  118.     #include "LFDictionary.c"
  119.     #include "LFArray.c"
  120.     #include "LFValue.c"
  121.     #include "LFNumber.c"
  122.     #include "LFString.c"
  123.     #include "LFRunLoop.c"
  124.     #include "LFTimer.c"
  125.     #include "LFRunLoopObserver.c"
  126.     #include "LFNotification.c"
  127.     #include "LFNotificationCenter.c"
  128. #endif
  129.  
  130. /**
  131.  * \defgroup __Global __Global
  132.  */
  133. /*@{*/
  134.  
  135. // --------------------------------------------------------------------------
  136. // Global functions
  137. // --------------------------------------------------------------------------
  138.  
  139. #ifndef _TARGET_LANG_LC_
  140. /**
  141.  * Allocates the two default allocators (LFAllocatorDefaultAllocator and LFAllocatorNullAllocator) and sets the LFAllocatorDefaultAllocator allocator as current allocator. <br />
  142.  * You usually call this function at the start of your application if you wish to make use of allocators. If you don't want to use them, or use just your own ones, you don't need to call this function<br />
  143.  * Available since v0.1<br />
  144.  * Change in v0.3.5: This function now also creates a LFRunLoopRef object.
  145.  **/
  146. static __inline void LFInit()
  147. {
  148.     LFAllocatorDefaultAllocator();
  149.     LFAllocatorNullAllocator();
  150.    
  151.     LFAllocatorSetCurrentAllocator(LFAllocatorDefaultAllocator());
  152.     LFRunLoopCreate();
  153. }
  154.  
  155. /**
  156.  * Releases the two default allocators together with all their allocated memory. <br />
  157.  * Available since v0.1 <br />
  158.  * Change in v0.3.5: This function now automatically stops the current run loop (if available).
  159.  @remark Call this function before you exit your application to avoid leaking memory.
  160.  **/
  161. static __inline void LFExit()
  162. {
  163.     LFAllocatorDestroy(LFAllocatorDefaultAllocator());
  164.     LFAllocatorDestroy(LFAllocatorNullAllocator());
  165.    
  166.     if(LFRunLoopCurrentRunLoop())
  167.     {
  168.         LFRunLoopStop(LFRunLoopCurrentRunLoop());
  169.         LFRelease(LFRunLoopCurrentRunLoop());
  170.     }
  171. }
  172.  
  173. /**
  174.  * Returns the current version as one integer. <br />
  175.  * The formular used for calculation is: (((major) << 16) | ((minor) << 8) | (patch)) <br />
  176.  * Available since v0.2
  177.  **/
  178. static __inline int LFVersion()
  179. {
  180.     return LFVersionCreate(LFVersionMajor, LFVersionMinor, LFVersionPatch);
  181. }
  182.  
  183. /**
  184.  * Returns the current version as human readable LFStringRef<br />
  185.  * Available since v0.2 <br />
  186.  * Change in v0.3.5: The function now returns an autoreleased string.
  187.  **/
  188. static __inline LFStringRef *LFHumanReadableVersion()
  189. {
  190.     char temp[193]; // 64 * 3 + 1 Character space. Thats the max size
  191.     sprintf(temp, "%i.%i.%i", LFVersionMajor, LFVersionMinor, LFVersionPatch);
  192.    
  193.     return LFStringWithCString(temp);
  194. }
  195.  
  196. #else
  197. void LFInit()
  198. {
  199.     LFAllocatorDefaultAllocator();
  200.     LFAllocatorNullAllocator();
  201.     LFAllocatorSetCurrentAllocator(LFAllocatorDefaultAllocator());
  202.    
  203.     LFRunLoopCreate(); // This will become the current runloop
  204. }
  205.  
  206. void LFExit()
  207. {
  208.     LFAllocatorDestroy(LFAllocatorDefaultAllocator());
  209.     LFAllocatorDestroy(LFAllocatorNullAllocator());
  210.    
  211.     if(LFRunLoopCurrentRunLoop())
  212.     {
  213.         LFRunLoopStop(LFRunLoopCurrentRunLoop());
  214.         LFRelease(LFRunLoopCurrentRunLoop());
  215.     }
  216. }
  217.  
  218. int LFVersion()
  219. {
  220.     return LFVersionCreate(LFVersionMajor, LFVersionMinor, LFVersionPatch);
  221. }
  222.  
  223. LFStringRef *LFHumanReadableVersion()
  224. {
  225.     char temp[193];
  226.     sprintf(temp, "%i.%i.%i", LFVersionMajor, LFVersionMinor, LFVersionPatch);
  227.    
  228.     return LFStringWithCString(temp);
  229. }
  230.  
  231. #endif
  232.  
  233. /*@}*/
  234.  
  235. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement