KFoundation  v2.1
A Better Foundation Library for C++
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
Overview (out of date)

KFoundation is a collection of C++ APIs that are essential to every program. Some of them like Logger have been missing in C++ standard libraries, and some of the like managed pointers (Ref) replace existing C++ standard APIs like auto_ptr, etc. with better fucntionality.

Most classes in KFoundation implement Streamer interface. This interface provides a toString() funtion and also overloads << operator for both ostream and logger stream. For example, if myObject is a Streamer, you can do any of the following:

LOG << myObject << OVER;
Ref<UString> str = myObject->toString();

The KFoundation APIs can be divided into the following categories (modules):

The following breifly explains the most essential APIs in each module.

Types and Macros

KFoundation defines a set of portable types. These are, kf_octet_t, kf_int8_t, kf_int16_t, kf_int32_t, and kf_int64_t.

There are a serries of macros helping to detect the operating system. Thesre are, KF_LINUX, KF_MAC, KF_MACH, KF_SOLARIS, and KF_FREE_BSD. If the target machine or operating system is supported by KFoundation, KF_SUPPORTED will be defined.

IS_NULL(X) and NOT_NULL(X) macros are provided to help creating more readable codes.

ISA(X), and AS(X) that are related to memory management module. Usage:

if(myObject.ISA(MyClass)) {

See all APIs here.

Memory Management

KFoundation provides an automatic memory management solution with several advantages. Only subclasses of KFObject can take advantage of this feature. Thus KFObject is the root class in KFoundation inheritance hierarchy. To create a pointer to a managed object use Ref<T>, RefConst<T> instead a standard one. See documentation for kfoundation::Ref for more details.

KFoundation memory management protects you from getting segmentation fault, and instread throws NullPointerException or InvalidPointerException as appropriate with complete stack trace that helps you debug your program or just keep it running without a crash.

If ever needed, you may interact with running memory managers by invoking System::getMasterMemoryManager(). You may create and register your own managers as well. A memory manager should be a subclass of MemoryManager.

See all APIs here.

Wrappers and Containers

Languages like Java offer type-wrapper classes corresponding to primitive types. These are useful when you need to use a variable of primitive type like an object. KFoundation offers Bool, Int, LongInt, Double, and UChar for the same purpose. Specially UChar contains a set of very useful functions to deal with Unicode and UTF-8 encoding.

At the moment, there are only two container classes, namely Array<T> and RefArray<T>. RefArray<T> is a container for ManagedObjects, and Array<T> is a container for everything else. However Array<T> is a KFObject itself. NummericVector<T> is a subclass of Array<T> that implements primary mathematical operations and implements Streamer interface i.e. it has a toString() method.

See all APIs here.


KFoundation offers InputStream and OutputStream classes as minimalist equivalant of standard ostream and istream. Thanks to their minimalist design, an extensive set of stream types could by provided by KFoundation. Thesre are, BufferInputStream, BufferOutputStream, FileInputStream, FileOutputStream, InternetInputStream, InternetOutputStream, and StringInputStream. If you need to use a standard istream or ostream object withing KFoundation simply use StandardInputStreamAdapter and StandardOutputStreamAdapter.

See all APIs here.

Object Serialization and Deserialization

KFoundation offers a powerful and intuitive way for objects to implement serialization and deserialization capabilities. To be serializable, objects need to implement SerializingStreamer interface. And to be deserializable they should implement StreamDeserializer interface. When implemented, these interfaces allow those object to be serialized/deserialized to and from every format that is supported by KFoundation, including XML, JSON, and KFOR.

To learn more about serialization read documentation for ObjectSerializer. And for deserialization check the documentation for Token class.

See all APIs here.


See all APIs here.

Range Arithmatics

If you usually work with multidimensional arrays and stencil copmutation, and specially if you do so in a distributed envrionment, these classes make your life much easier.

Tuple represents an element in n-dimentional array. It implements a large range of mathematical operations. Range is a range of indexes. This class can divide your range into desired pieces, analyse borders, detect overlapping and adjecent ranges and so on.

RangeIterator is an exciting feature that summarizes all your for loops into one small one, and is suplemented by ProximityIterator to make stensil computation with C++ as easy as it had never been.

See all APIs here.


KFoundation exceptions provide serializable (also printable) stack trace. The root class for all exceptions is KFException. You may define your own exception. Remember to always call setName() method once in constructor if you do so.

See all APIs here.