CCore General

Source code organization

Most of CCore declarations are enclosed in the namespace CCore. There are several inner namespaces, like Meta, Net, Math, Sys, Crypton, DDL.

Source code is split into several major parts: Simple, Fundamental, Applied, HCore, XCore and Target. First five are located in the same named directories in the CCore root. Last one is located in the directory Target/<TargetName>. Tools are located in the directory tools.

Source code parts consist of three directories : inc, src, and test. So to include a CCore header write


#include <CCore/inc/...>

Each CCore .h file has a correspondent .cpp file, even if it defines nothing.

Each target is either HCore or XCore target, so it includes only one part: HCore or XCore.

HCore targets are host targets, XCore targets are device targets.

CCore-based projects

To create a CCore-based project select a directory for it. Then place in this directory (or in subdirectories) a source code. Two source files must not have the same name, even if they are in different subdirectories. You may use files with extension ".cpp" for C++ source files ans ".s" for assembler source files. Create the Makefile. Select and create a subdirectory for object files (and other intermediate files), usually obj. Then issue the command make from the Cygwin console. If you change the source file set, then issue the command make list.

Here is an example of Makefile.


CCORE_ROOT = ../..

CCORE_TARGET = WIN32

OBJ_PATH = obj

TARGET = Application.exe

include $(CCORE_ROOT)/Target/Makefile.app

run: $(TARGET)
	$(TARGET)

You have to define the following variables.

CCORE_ROOT is the path to the CCore root directory.

CCORE_TARGET is the target name.

OBJ_PATH is the path to the object file directory. This variable can be omitted, in this case the default value "." is used.

TARGET is the application file name. This variable can be omitted, in this case the default value "main.exe" is used.

The following "magic line" must follow:

include $(CCORE_ROOT)/Target/Makefile.app

For your convenience you may include optional make targets like run above.

There are additional optional variables you may define.

SRC_PATH_LIST — the list of source file directories. It is "." by default.

CCOPT_EXTRA — additional options for the C++ compiler. It is empty by default.

LDOPT_EXTRA — additional options for the linker. It is empty by default.

If you want to build a libray, not an executable, then use another "magic line":

include $(CCORE_ROOT)/Target/Makefile.lib

Names and decorations

All global entities have capitalized names. I.e. class names, global objects etc. Local object names, non-static members and method names start from lowercase letters.

Here is an example of the class definition:


class SomeClass
 {
   int item_count;

  public:

   int getItemCount() const { return item_count; }

   void setItemCount(int item_count_) { item_count=item_count_; }
 };

The private part goes first, the public is last. Members are decorated like "item_count". Methods like "getItemCount()". Getters like "getItemCount()" and setters like "setItemCount()". The argument, used to initialize the member "item_count", named as "item_count_".

Suffixes are used to name variants:


struct MemBase;

struct MemBase_nocopy;

Sections are used to group members:


class Sem : public Funchor_nocopy
 {
   .... 

  public:
   
   // constructors
  
   explicit Sem(ulen count=0);
   
   explicit Sem(TextLabel name,ulen count=0);
   
   ~Sem();
   
   // give
   
   void give();
   
   void give_many(ulen dcount);
   
   // take
   
   bool try_take();
   
   void take();
   
   bool take(MSec timeout);
   
   bool take(TimeScope time_scope); 
    
   // functions
   
   Function<void (void)> function_give() { return FunctionOf(this,&Sem::give); }
 };

The popular words are: "count", "len", "obj", "try...", "zstr", "d..." to designate a delta value.

A loop for example:


for(ulen i=0,count=....; i<count ;i++) { .... }

Another example:


for(ulen i=count; i-- ;) { .... }

operator + and the "null" state

There are many types, which have a special state — "null" state. Usually for such types the default constructor creates a "null" object. CCore often defines the Nothing-constructor to do the same. And two operators: operator + and operator ! can be used to check, if the object is "null".


class SomeClass
 {
  public:

   SomeClass(); // set the object into the "null" state

   SomeClass(NothingType); // set the object into the "null" state too

   boolable operator + () const; // return true, if the object is not "null"

   bool operator ! () const; // return true, if the object is "null"
 };