Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // LiteFoundation.h
- // Lite Foundation
- //
- // Copyright (c) 2010 by Sidney Just
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
- // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
- // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- // and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
- // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- /*! \mainpage Lite Foundation framework reference
- *
- *
- * \section intro_sec Introduction
- * This is the reference for the Lite framework library. The Lite Foundation framework is a library of common used functions and types. <br>
- * It is written in plain C and should run on every machine that provides the standard C library.
- * <br>
- *
- * \section usage_sec Usage
- * 1) Include the LiteFoundation.h header<br>
- * 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>
- * 3) No third step ;)
- * <br>
- *
- * \section changes_sec Change log
- * <b>Version 0.4:</b><br />
- * * Added the LFNotificationCenterRef object. <br />
- * * Added the LFNotificationRef object. <br />
- * * Added functions to read and write LFDataRef objects from and to files. <br />
- * * Fixed a bug with LFDictionaryRef and the LFCoder. <br />
- * <br />
- * <b>Version 0.3.5:</b><br />
- * * Added the LFRunLoopObserverRef object. <br />
- * * Added the LFAutorelease() function. <br />
- * * Added functions that create autoreleased objects <br />
- * * Moved the LFTimerRef fire logic from the run loop to the LFTimerRef object. <br />
- * * Fixed a bug with LFRunLoopRunUntilDate() function <br />
- * <br />
- * <b>Version 0.3.4:</b><br />
- * * Added the LFDateRef object. <br />
- * * Added the LFRunLoopRef object. <br />
- * * Added the LFTimerRef object. <br />
- * * Added the LFDescription() function. <br />
- * <br />
- * <b>Version 0.3:</b><br />
- * * Added serialization for LFDictionaryRef. <br />
- * * Added functions to use a CString key as key for an LFDictionaryRef (LFDictionaryAddCKeyAndValue() and LFDictionaryValueForCKey())
- * * Added a function to compare two Lite Foundation object. It doesn't only compare their pointers but also their contents (LFTypeIsEqual()) <br />
- * * Added a function for generating an LFDataRef out of a subset of another LFDataRef (LFDataGetDataInRange()) <br />
- * * Added two functions to the LFNumberRef that allows you to store and receive pointer addresses (LFNumberCreateWithPointer() and LFNumberPointerValue()) <br />
- * * Added zombies to make crashes because of object over-releasing easier (LFEnableZombies()) <br />
- * * Changed the LFDictionaryRef so that it now checks the content of an key instead of just checking the pointer. <br />
- * <br />
- * <b>Version 0.2:</b><br />
- * * Added the LFDictionaryRef object for Lite-C <br />
- * * Added better version handling <br />
- * * Added a few functions for the LFStringRef to make it easier to work with pathes and manipulate string objects. <br />
- * * Changed the LFArrayHasObject() function name to LFArrayContainsObject(). However, LFArrayHasObject() is still available als macro that calls LFArrayContainsObject. <br />
- * * 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 />
- * * 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 />
- * <br />
- * <b>Version 0.1:</b><br />
- * * Initial release.<br />
- *
- * <br>
- */
- #ifndef _LITEFOUNDATION_H_
- #define _LITEFOUNDATION_H_
- #include "LFAPI.h"
- // --------------------------------------------------------------------------
- // Defines
- // --------------------------------------------------------------------------
- #define LFVersionMajor 0
- #define LFVersionMinor 4
- #define LFVersionPatch 0
- #define LFVersionCreate(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
- // --------------------------------------------------------------------------
- // Includes
- // The default Lite Foundation includes
- // --------------------------------------------------------------------------
- #include "LFAllocator.h"
- #include "LFType.h"
- #include "LFCoder.h"
- #include "LFAutoreleasePool.h"
- #include "LFData.h"
- #include "LFDate.h"
- #include "LFDictionary.h"
- #include "LFArray.h"
- #include "LFValue.h"
- #include "LFNumber.h"
- #include "LFString.h"
- #include "LFRunLoop.h"
- #include "LFTimer.h"
- #include "LFRunLoopObserver.h"
- #include "LFNotification.h"
- #include "LFNotificationCenter.h"
- #ifdef _TARGET_LANG_LC_
- #include "LFAllocator.c"
- #include "LFType.c"
- #include "LFCoder.c"
- #include "LFAutoreleasePool.c"
- #include "LFData.c"
- #include "LFDate.c"
- #include "LFDictionary.c"
- #include "LFArray.c"
- #include "LFValue.c"
- #include "LFNumber.c"
- #include "LFString.c"
- #include "LFRunLoop.c"
- #include "LFTimer.c"
- #include "LFRunLoopObserver.c"
- #include "LFNotification.c"
- #include "LFNotificationCenter.c"
- #endif
- /**
- * \defgroup __Global __Global
- */
- /*@{*/
- // --------------------------------------------------------------------------
- // Global functions
- // --------------------------------------------------------------------------
- #ifndef _TARGET_LANG_LC_
- /**
- * Allocates the two default allocators (LFAllocatorDefaultAllocator and LFAllocatorNullAllocator) and sets the LFAllocatorDefaultAllocator allocator as current allocator. <br />
- * 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 />
- * Available since v0.1<br />
- * Change in v0.3.5: This function now also creates a LFRunLoopRef object.
- **/
- static __inline void LFInit()
- {
- LFAllocatorDefaultAllocator();
- LFAllocatorNullAllocator();
- LFAllocatorSetCurrentAllocator(LFAllocatorDefaultAllocator());
- LFRunLoopCreate();
- }
- /**
- * Releases the two default allocators together with all their allocated memory. <br />
- * Available since v0.1 <br />
- * Change in v0.3.5: This function now automatically stops the current run loop (if available).
- @remark Call this function before you exit your application to avoid leaking memory.
- **/
- static __inline void LFExit()
- {
- LFAllocatorDestroy(LFAllocatorDefaultAllocator());
- LFAllocatorDestroy(LFAllocatorNullAllocator());
- if(LFRunLoopCurrentRunLoop())
- {
- LFRunLoopStop(LFRunLoopCurrentRunLoop());
- LFRelease(LFRunLoopCurrentRunLoop());
- }
- }
- /**
- * Returns the current version as one integer. <br />
- * The formular used for calculation is: (((major) << 16) | ((minor) << 8) | (patch)) <br />
- * Available since v0.2
- **/
- static __inline int LFVersion()
- {
- return LFVersionCreate(LFVersionMajor, LFVersionMinor, LFVersionPatch);
- }
- /**
- * Returns the current version as human readable LFStringRef<br />
- * Available since v0.2 <br />
- * Change in v0.3.5: The function now returns an autoreleased string.
- **/
- static __inline LFStringRef *LFHumanReadableVersion()
- {
- char temp[193]; // 64 * 3 + 1 Character space. Thats the max size
- sprintf(temp, "%i.%i.%i", LFVersionMajor, LFVersionMinor, LFVersionPatch);
- return LFStringWithCString(temp);
- }
- #else
- void LFInit()
- {
- LFAllocatorDefaultAllocator();
- LFAllocatorNullAllocator();
- LFAllocatorSetCurrentAllocator(LFAllocatorDefaultAllocator());
- LFRunLoopCreate(); // This will become the current runloop
- }
- void LFExit()
- {
- LFAllocatorDestroy(LFAllocatorDefaultAllocator());
- LFAllocatorDestroy(LFAllocatorNullAllocator());
- if(LFRunLoopCurrentRunLoop())
- {
- LFRunLoopStop(LFRunLoopCurrentRunLoop());
- LFRelease(LFRunLoopCurrentRunLoop());
- }
- }
- int LFVersion()
- {
- return LFVersionCreate(LFVersionMajor, LFVersionMinor, LFVersionPatch);
- }
- LFStringRef *LFHumanReadableVersion()
- {
- char temp[193];
- sprintf(temp, "%i.%i.%i", LFVersionMajor, LFVersionMinor, LFVersionPatch);
- return LFStringWithCString(temp);
- }
- #endif
- /*@}*/
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement