Taxonomy of classes

This page provides the list of common terms and the taxonomy of classes. Class in C++ is a very generic and powerful entity, so we classify them by their purpose and nature.

Terms

Efficient means O(1)-nothrow. I.e. it is a sequence of operations, which has a definite, reasonably small execution time limit and always successful.

Derivability is the ability of some entity to be used as the building block of the whole. See, for example, Swap.

Classification

Word

Word is a enumerator, purposed to verbose some generic action. In C++ there are no named constructors. But it is possible to add an unused argument of a Word type to clearly distinguish between different overloaded constructors. See, for example, Nothing.

Guard function

Guard function ensures some condition. If the required condition is not true, an exception is thrown. See, for example, GuardIndex(). Usually, we define a guard function by the following pattern:


void GuardXXXCCC(<arg_list>); // exception throwing function

void GuardXXX(<arg_list>) // guard function 
 {
  if( <not condition> ) GuardXXXCCC(<arg_list>);
 }

Class methods can also be guard methods.

Abort function

Abort function aborts execution with some diagnostic message. For example, NoObjectAbort() is called when the requested object has not been initialized.

Creator function

Creator function creates some object. Normally we create an object using its class constructor. But if we are using class templates, we have to provide a template argument list. Using Creator function allows infer this list from the function argument types. See, for example, MakeTuple():


template <class ... TT>
Tuple<TT...> MakeTuple(const TT & ... tt);

Partial class

Partial class is a class not intended for a direct usage, but designed to be a building block for a derived class. Like a sophisticated machine, built from a machine parts, in C++ a complex class can be constructed from smaller and simpler classes. Sometimes such parts are not usable alone. Hence we call them Partial. See, for example, ToMemBase. Such classes often have names ending in "Base".

Small Data Type

Small Data Type is a type like basic types with a small state and data semantic. These types have efficient copy constructor and assign operator.


struct Point
 {
  int x;
  int y;
 };

Data Type

Data Type is a type with data semantic, but with an arbitrary large state. The simplest example is the class String. The purpose of such types is to store some piece of data. The data is stored in some owned buffer. They may have the copy constructor and the assign operator. These operators can be implemented as efficient operations using reference counting. In CCore we don't make a class copyable if there is no way to make it efficient. In such situation the class is not copyable, but usually swappable/movable.

Resource Host Type

Resource Host Type is a wrapper over some resource handle, like a file descriptor, a socket descriptor, any other OS object descriptor, object pointer, memory block pointer etc. In destructor the handle is released. The purpose of such types is to ensure the resource will be eventually released. It also provides some methods to use the resource. Resource Host Types are not copyable, but swappable/movable.

Scope Lock Type

Scope Lock Type objects are used to "lock" something for the duration of a scope. For example, the Mutex::Lock object is used to lock a mutex:


Mutex mutex;

{
 Mutex::Lock lock(mutex);

 ....
}

Scope Lock Type performs some "entry" operation in its constructor and then when scope is exited by any way some "leave" operation in its destructor.

Container Type

Container Type is a class, purposed to store another objects. Container not only provides a storage, but also controls the life-time of contained objects.

Resource Provider Type

Resource Provider Type is a class, purposed to distribute some resource. For example, the memory. Usually, all taken resources must be given back before the provider object is destroyed.

Pointer Type

Pointer Type "points" to another object. It gives access to the object functionality.

Cursor

Cursor can iterate through a set of objects. In CCore the following interface is used for cursors:


class Cursor
 {
  public:

   boolable operator + () const; // cursor points to an object

   bool operator ! () const; // cursor is stopped, == !+(*this)

   void operator ++ (); // move to the next object, precondition( +(*this) )

   // reference variant, can be read-only

   T & operator * () const; // the current object, precondition( +(*this) )

   T * operator -> () const; // the current object, precondition( +(*this) )

   // value variant, always read-only 

   T operator * () const; // the current object, precondition( +(*this) )
 };

Here is a typical cursor loop:


R r=....;

for(; +r ;++r) { do_with(*r); }

Range Access Interface

Range Access Interface is the interface, used to present a range of objects:


class SomeClass
 {
  public:

   T * getPtr();
   
   const T * getPtr() const;
   
   const T * getPtr_const() const;
   
   ulen getLen() const;
 };

Usually, this interface is implemented by Container Types or some Proxy Types.

Object Pointer Interface

Object Pointer Interface is implemented by Pointer Types to give access to the pointee object:


class SomeClass
 {
  public:

   boolable operator + () const; // points to an object
   
   bool operator ! () const; // no object, == !+(*this)
  
   T * getPtr() const; // the current object, precondition( +(*this) )
   
   T & operator * () const; // the current object, precondition( +(*this) )
   
   T * operator -> () const; // the current object, precondition( +(*this) )
 };

This interface can be reduced to


class SomeClass
 {
  public:

   T * getPtr() const; // the current object
   
   T & operator * () const; // the current object
   
   T * operator -> () const; // the current object
 };

if the class cannot be in the null state.

Property Type

Property Type is a kind of classes, providing some properties and meant to be used as the base to inherit these properties by a derived class. For example, see NoCopy or MemBase.

Helper Type

Helper Type is a type, designed to do some job, usually objects of such types are temporary, or local objects. See, for example, PrintSetType. Helper Types are used instead of functions, in such cases, where, for instance, the object is required, like in the example above.

Proxy Type

Proxy Type is close to the Helper Type. Objects of such types are used to do some job on behalf of another type object.

Device Type

It is not easy to explain the term Device Type. The simplest example is a printing device. It is a class, putting characters into some output storage (for example, a file). Or serialization/deserialization devices. Another example — packet processing devices, like PTP protocol device classes. You can image some mechanical device, doing some job. If you can think about some class like about such device, it is likely a Device Type.

Algorithm Package

Algorithm Package is a stateless class, containing definitions of constants, types, functions. It is purposed to serve as a template argument to provide an implementation of something. It allows to customize templated definitions in a very flexible manner. Such class can be huge or small. See, for example, OwnAlgo.

Class-function

Class-function is a class, used as a function. Its constructor is a function body. The constructed object is a return value. Such classes are useful if you have to return a large or non-copyable object. See, for example, MemStat.

Meta-class

Meta-class is a class, used to present the result of a meta-calculation. It contains only static members, like constants, types or static functions.

Meta-function

Meta-function is a class template, instantiation of meta-function produces a meta-class. Usually, Meta-function are defined using partial or complete specialization. Here is the Meta::SelectCtor:


template <bool Cond,class T1,class T2> struct SelectCtor;

template <class T1,class T2>
struct SelectCtor<true,T1,T2>
 {
  using Ret = T1 ;
 };

template <class T1,class T2>
struct SelectCtor<false,T1,T2>
 {
  using Ret = T2 ;
 };

Meta-constant

Meta-constant is a constant template. Here is the MaxUInt.


template <class UInt,class=Meta::EnableIf< Meta::IsUInt<UInt> > >
const UInt MaxUInt = UInt(-1) ;

Meta-type

Meta-type is a type template. Here is the Meta::Select.


template <bool Cond,class T1,class T2>
using Select = typename SelectCtor<Cond,T1,T2>::Ret ;