C++ library designed especially for embedded system with very limited resources, e.g. 32kB RAM. Test driven development was used for all parts of this library. You can find all tests in this folder.

Library is divided to more parts:

Basic Types

All classes are optimized for Atmel. Atmel compiler does not have a proper support of virtual functions, therefore no virtual functions are used here.

Class name Memory allocation Description
TString static/dynamic simple string with possibility to allocate memory in both ways - statically or dynamically, maximum length is limited to 65535
TShortString static simple string allocated statically, maximum length is limited to 40 characters
TCustomString static simple string allocated statically, you can define your own maximum length
TStringList dynamic class for handling string list in one big memory block terminated by double zero
TParamString none class for parsing parameters from one long string (e.g. "length:1;name:john")
TFilePath static class for handling file names (e.g. changing file extension, extracting file path, combining two file paths etc.)
TRandom none class designed for generating random numbers
TDate none date calculations
TTime none time calculations
TDateTime none date and time calculations at once


Collections

All classes are designed to achieve low memory fragmentation - always is allocated a bit more memory than needed and memory is reallocated again when memory is not big enough.

Container classes are implemented with both STL like interface and .NET like interface, it is up to you which one do you like more. Therefore you can start using them very quickly without learning how to use them. With this library you no longer need to use STL, this library can be used as a light weigth STL replacement.

Class name Memory allocation Description
TArray none Read only array. Any editable collection (TList, TDictionary etc) can be modified to this non editable array by method ToArray().
TDictionary dynamic Dictionary compatible with both STL and .NET. Each dictionary item has a key and value.
TEnumerator none TEnumerator was added to achieve more similarity with .NET. It can iterate all items. It is implemented by all collection classes.
TList dynamic List compatible with .NET List and STL vector. This is just an array of items of defined data type. You can choose the data type.
TObjectList dynamic List designed for storing class instances.
TPair none Used by TDictionary. It is compatible with STL pair, it contains the key ("first") and the value ("second")
TQueue static Queue class compatible with .NET queue and STL queue
TSortedDictionary dynamic Similar to TDictionary, but keys are internally sorted, therefore key should be found faster.
TStack dynamic Stack class compatible with .NET stack and STL stack
TStaticList static List with static memory allocation. Dynamic memory allocation is never used.
TStaticDictionary Static Dictionary with static memory allocation
TEnumerable None Almost all collection classes implement this interface.


FileUtils

classes for reading and writing data from/to generic source. This can be a file, RAM, ROM, EEPROM, Flash ROM or generic handle (e.g. serial port, pipe or tcp/ip socket). Cache or compression algorithm can be applied to this generic source (or target) also. This library also includes classes for working with simple text file, xml file or json file.

Stream classes (generic data source - only very small part data is in memory at once)

Class name Memory allocation Description
TStream none Base class for all streams. This class contains method for reading/writing various data types from/to stream.
TFileStream none Reading/writing data from/to file. Internally it uses C functions fopen, fread, fwrite, fseek, fclose
THandleStream none Reading/writing data from/to generice file handle. Handle can be linked with serial port, pipe etc.
TMemoryStream static/dynamic Reading/writing data to specific RAM memory block.
TROMStream none Reading data from specific ROM memory block. Writing operations are not allowed.
TEEPROMStream none Reading/writing data from specific memory block via callback functions.
TCachedStream static/dynamic Stream decorator. Data are not written until cache is full or data are read to cache first until cache is full. This can be used for reading/writing data to Flash memory.
TLZ77Stream static/dynamic Stream decorator, it already contains internal cache (like TCachedStream). It writes data to cache first, data are compressed when cache is full and then are written to parent stream. Reading works in similar way - data are read to cache, cache content is decompressed and then data from cache are being used until cache is empty.

File classes (working with whole file - whole file is in memory at once):

Class name Memory allocation Description
TTextFile static/dynamic Reads text file line by line
TXmlDoc static/dynamic Reads xml document from file to memory. Also can be used for creating new xml document and saving it back to file.
TXmlTag none Holds data about one xml tag. Data are usually a pointer to memory block allocated by TXmlDoc class or xml pool. Class uses simplified XPath syntax for searching sub tags .
TXmlTagBasePool none This class creates new instances of TXmlTag.
TXmlTagDynamicPool dynamic It uses dynamic memory allocation for creating new instances of TXmlTag.
TXmlTagStaticPool static It uses preallocated (static) memory block for creating new instances of TXmlTag. Number of instances is limited.
TJsonDoc static/dynamic Reads json document from file to memory. Also can be used for creating new json document and saving it back to file.
TJsonTag none Holds data about one json tag. Data are usually a pointer to memory block allocated by TJsonDoc class or json pool.
TJsonTagBasePool none This class creates new instances of TJsonTag.
TJsonTagDynamicPool dynamic It uses dynamic memory allocation for creating new instances of TJsonTag.
TJsonTagStaticPool static It uses preallocated (static) memory block for creating new instances of TJsonTag. Number of instances is limited.


Graphics

Classes for drawing basic geometric shapes, images and texts. All geometic shapes and all fonts use antialiasing for smoother look and feel.

Classes for drawing images:

Class name Memory allocation Description
TGraphicsData dynamic Base class for all images. This class can load/save just its own data format, it can hold an image with any pixel format or any size.
TWindowsBmpFile dynamic Descendant of TGraphicsData. This class can load Windows Bitmap and converts it to internal datastructures, also can save data back to Windows Bitmap.
TPixelFormatConverter none Converts source pixel format to target pixel format. E.g. converts 24bit windows bitmap to 16bit format of LCD display.
TDxtBlockCreator none Used internally by TPixelFormatConverter, see S3TC compression, DXT1 format. This class is used for conversion to DXT1 format when target pixel format is pfDXT1.
TCachedWindowsBmpFile dynamic Designed for working with large windows bitmap files. Only small part of data is in memory at once.

Drawing to video RAM:

Class name Memory allocation Description
TCanvas none Provides operations like DrawText, DrawLine, DrawEllipse, DrawImage etc. Target memory and target pixel format is defined by TGraphicsData instance required by constructor
TFont none Works with font description created by EmbeddedFontEditor
TFontCharacter none Description of one font character


Math

Classes for fixed-point arithmetics.
Class name Memory allocation Description
TFixedPoint16M none 32 bit fixed point value with range -16777216.000 to 16777215.995
TFixedPoint1024 none 32 bit fixed point value with range -1024 to 1023.999999
TFixedPoint128 none 32 bit fixed point value with range -128 to 127.9999999


Persistence

Serialization library

Classic way how to do persistence is to write a set of methods for

Classic paradigm (NOT USED IN THIS LIBRARY!)
BinaryLoad Loads binary data
BinarySave Saves binary data
XML parsing (e.g. SAX event parser) Parses XML
XML creating (simple text output) Creates XML

THIS LIBRARY IS NOT USING THIS PARADIGM, because writing several separated method increases risk of human errors at both sides pc side and embedded device side. It is really not easy to maintain such source code, therefore this paradigm means never ending series of mistakes and wrongly imported data or even lost data if source code maintenance is not done very carefully.

Therefore a NEW PARADIGM is used in this library. It is enough to implement just one serialization method

New paradigm (used in this library)
Serialize This single method takes care about binary load, binary save, xml parsing, xml saving + creating xsd description of all datastructures

void ClassB::Serialize(unsigned short version)
{
    SerializeString ("Username", UserName, false, 6, 24);
    SerializeShortInt("Pin", Pin);
    SerializeShortInt("Delay", Delay);
    SerializeUID ("UserGroupUID", (void**) &AssignedGroup, true, &MainObject::MainManager.ManagerC);
    SerializeUIDArray("AssignedKeypads", (void**) &AssignedKeypads, 0, &MainObject::MainManager.ManagerD);
}

There are various versions of Serilize methods for various data types. Additional parameters are used for:

- range checking during loading (therefore minValue and maxValue is an optional parameter)

- writing minValue + maxValue to xsd description

See example of xml output, xsd output and example application for more information.


Protocols

This part contains classes for generic binary protocol, generic text protocol, various kinds of loggers and support of TCP/IP + UDP socket on both Windows and Linux.

Logger classes:

Class name Description
TLog Basic class of all kinds of logs.
TConsoleLog Output to standard console window
TFileLog Output to file
TUDPLog_Linux Output to broadcasted UDP packets on Linux platform

Signalling (a bit similar to Qt signals and slots):
Class name Description
TEventSender Class is used for emitting events. Events can be received by TEventReceiver class.
TEventReceiver Class is used for receiving events. "Connect" method is used for subscribing events from TEventSender, since then subscribed events are passed from TEventSender to TEventReceiver.
TEventSerializer This class is normally not used by TEventReceiver nor TEventSender. Serializer can be used for logging events or for sending events to another computer, e.g. via Tcp/ip or serial port.

Generic protocols:
Class name Description
TBinaryProtocol Generic binary protocol. See basic idea for generic binary protocols
TTextProtocol Generic text protocol. This protocol uses simple text format, e.g. "Name:'John Doe';Age:30;" - all parameters have a name and there must be a separator (e.g. ; ) at the end of each value.
TcpClient_Linux Linux TcpClient in form of user friendly class
TcpClient_Win Windows TcpClient in form of user friendly class
TcpServer_Linux Linux TcpServer in form of user friendly class
TcpServer_Win Windows TcpServer in form of user friendly class
UdpClient_Linux Linux UdpClient in form of user friendly class
UdpClient_Win Windows UdpClient in form of user friendly class