Technical Article

KFoundation POSIX Edition: Main Features Overview

2020-09-22 v1.0

C++: The Revolution

When evolution can't do enough, it is time for a revolution. It is time for C++ to get a fresh new skin, and the dignity it deserves. That is why the KFoundation is here. It is an elegant, fast, and easy-to-learn replacement for C++ standard libraries, and can help making C++ a viable choice against Java and other languages.

Key Features

Let there be no pointers!

  Ref<MyClass> myObject = new MyClass();

Instead of all sort of pointers, KFoundation has only one type of reference, Ref<T>. It is based on an innovative concept called Globally Unique Reference or GUR. It is half the size of shared_ptr, and is faster in many aspects. It proactively detects and prevents segmentation faults by throwing an exception instead. There is a whole new level of elegance in type-casting too:


What's even cooler? GUR can be used to reference objects from remote nodes in the network. It is secure and safe: it never reveals the actual memory addresses, and is smart enough to detect inconsistencies, for example when a given pointer is bogous or when the referened object is deleted or replaced.

One UString to rule them all

  Ref<UString> myStr = K"I can " + *myObject + " like Java, and store in UTF-" + 8;

UString is the only string class you need. It internaly uses UTF-8 encoding, which means minum memory consumption and fastest I/O: no byte order conversion, and in most cases, no encoding conversion is needed. It can be concatenated to almost everything. It comes with convernient UCharIterator to traverse over variable-length characters. It is so optimized that it can resuse the same buffer for substrings, to save more memory.

I/O streams: more quality and more quantity

  Ref<InternetOutputStream> output = new InternetOutputStream(ipAddress);
  PrintWriter(output) << K"Huston! We have an object: " << *myObject << OVER;

The I/O stream base classes are made to be easily extensible. A large variety of them are already included in KFoundation to stream to, and from files, buffers, strings, and even the Internet. All the formatting functions are moved to a single PrintWriter class that can write anything on any kind of stream. There is also a very versatile parser class that makes it easy to read anything. This is how we say "Hello World!" in KFoundation:

  System::OUT << K"Rock The World!" << OVER;

One stop to XML, JSON, and more


Any object that implements SerializingStreamer interface can be serialized to any stream in any supported format, and any object that implement StreamDeserializer can be read from any stream in any supported format. The built-in formats are XML, JSON, and KFOR (KFoundation Format). But adding addional user-defined formats are also very easy.

Over 80 portable classes, made with love

KFoundation is compatible with any standard C++98 above compiler. Its header files are not contaminated by the conventional standard C++ library, and its binary hardly relies on cstdlib. The size of its types are platform-independant, and so is its UString. Its APIs are made to be elegant, easy, and fast at the same time. See the complete list here.