Monday, October 7, 2024

Rudiments 2.0.0 Release Announcement

Version 2.0.0 of Rudiments, the C++ class library for developing systems and applications, is now available.

This release contains a tremendous number of changes and improvements...


Object

Much like Java, nearly every class now inherits from a base object class. This eliminates the need for some awkward void pointers, simplifies a bunch of internals, and facilitates a wastebasket class. Speaking of which...

Wastebasket

Ever need to create an arbitrary collection of objects, down in the depths of some body of code, and hang on to them until some higher level code is done with them? If that sounds abstract... In an MVC architecture, have you ever created a container full of objects way down in a DAO implementation and needed them to hang around until the view was done with them? In languages with garbage collection, they'll just hang around on their own until nobody needs them any more, but it's more complex than that in C++. The wastebasket class allows you to attach objects (children of the object class) to the wastebasket for bulk disposal later. You can create an arbitrary set of objects, throw them to the wastebasket, pass them back up to wherever, and continue to use them until you empty the wastebasket, at which point they'll all be destroyed.

MVC Framework

Speaking of DAO implementations and views... Rudiments 2.0.0 provides a basic MVC framework, which provides base classes for building out MVC applications. For example, there's an mvcsecurity class, an httpbasicsecurity implementation, an mvcproperites class that provides support for java-style properties files, mvccontroller, mvcview, mvcservice, and mvcdao classes, an mvcresult class for passing data up from mvcdao implementations, and an mvccrud class that defines an interface for classes that implement the CRUD paradigm. A resourcepool class is also provided for managing shared pools of resources.

Collection Overhaul

The collection classes (lists, trees, dictionaries, arrays, etc.) have undergone a major overhaul. Everything inherits from a base collection class now, which implements a bunch of functionality common to all containers. You can set a comparator to be used in sorting (eg. to sort in a non-sequential, "natural", or reverse order). Collections can be read-only, block/unit-based, or sequential-only.

Most notably though, a collection can now either "manage" its values or not. A collection that manages its values deletes them when the collection itself is deleted, and in the case of node-based collections like lists and trees, values are deleted when nodes are removed. In a dictionary, keys can also be managed. In rudiments 1.4, there were methods that you could call to delete or array-delete keys and values before deleting the collection, but this is a cleaner strategy.

There are also 2 new collections: table and scalar. The table container implements a table, with rows, columns, and column names. The scalar collection is a degenerate collection that only stores one value - useful when you have a single value but want to use a class that only operates on collections.

Character Set Improvements

Rudiments 1.4 had wcharacter/wcharstring/wstringbuffer classes. Rudiments 2.0 improves them and adds ucs2character/ucs2charstring/ucs2stringbuffer classes. Translation between character sets is improved as well. For example you can wcharstring::copy() or wcharstring::duplicate() an ascii or utf2 string, and vice-versa. The filedescriptor class provides methods for reading and writing wchar and ucs2 characters and strings. There's an iconvert class for translation of characters and strings between character sets. There's also a new locale class for managing locales and locale components.

Shutdown Flag

When an app crashes or receives a signal telling it to shut down, the signal handler shoudn't really be responsible for actually shutting down the app. Signal handlers really shouldn't do very much, at all! Arguably, a signal handler ought to just set a flag, the rest of the app should check for that flag in various places, and shut the app down gracefully if the flag was set. I've implemented that paradigm independently a dozen times, and finally decided to move it up into rudiments.

The process class now provides a set of methods like setShutDownFlagOnCrashOrShutDown() which just set a flag if a signal is caught that would crash or shut down the process, and also provides a getShutDownFlag() method to query that flag. Rudiments methods that retry on EINTR check this flag, and bail if it was set.

Block-Aligned and mmap() Buffering

The filedescriptor class can now differentiate between streams and storage, and buffer differently depending on which the descriptor is. If setIsStream(true) is called (the default) then it buffers the way it always has. If setIsStream(false) is called (for storage), then it aligns its buffers with block boundaries, and will use mmap(), when possible, if setMmapBufferingEnabled(true) is called. The various setPositionRelativeTo*() methods also now work as expected when buffering of storage is enabled.

byte_t

Historically, rudiments used unsigned char to represent a byte. Now there's a proper byte_t type that represents a byte.

Verbs

Methods tend to do things, and, as such ought to be verbs. Lots of methods have been renamed such that they "do" things now - eg. getIntegerLength() instead of integerLength(). Other methods that just describe a state or condition at least start with "is" - eg. isSupported() instead of supported().

Size, Length, and Count

For a long time, Rudiments (along with many other software projects) have confused size, length, and count. In Rudiments 2.0.0, size refers to the number of bytes, length to the number of characters, and count to the number of items. Eg. a ucs2 string might have a size of 10 but a length of 5. A linked list containing 5 ucs2 strings would have a count of 5. Method names and parameters have been overhauled, project-wide.

Bug Fixes and Improvements

The list of bug fixes and internal improvements could go on for days. Nearly evey class has been overhauled, updated, examined, or at least touched in some way. See the ChangeLog enclosed with the source distribution for the gory details.