conzept 16 C++ interface

With the DLL interface and the external programming interface, conzept 16 already offers options for implementing conzept 16 applications partially or even completely in other programming languages. These interfaces are available in the C programming language. This language has the advantage that, due to its simplicity, there is a corresponding compiler for almost every platform. However, this simplicity also represents its limitations: It is not object-oriented. This article presents a new, alternative interface in the C++ programming language, which not only benefits from the object orientation of the language.

We are in the final stages of developing the C++ interface and are pleased to present it here. We would like to invite you to use the comments function to tell us your opinion, suggestions, questions or criticisms about this new project.

Introduction

The C++ interface can be used to implement both supplementary extensions and stand-alone applications with the C++ programming language: An extension supplements the procedures of an existing conzept 16 application with functions that are outso urced to a dynamic library (under Windows: DLL). An application is an independent tool that can also access databases without calling procedures.

The interface is based on established C++ programming concepts:

    b

  • Exceptions for signaling error states
  • Iterators for loop processing
  • Streams for input and output
  • Class and function templates for implementing similar classes or functions

All elements of the C++ interface are described in an english-language documentation consisting of several HTML pages (start page: index.html). It is available for download at the end of this article. It also contains examples, limited to the essentials, of the use of functions requiring explanation, which are intended to provide a quick understanding of the types and functions concerned.

All types (classes, enumerations, etc.) of the C++ interface are located in the C16 namespace. Some other types are organized in subordinate namespaces.

Data types

The namespace C16::Value contains all data types that can be processed with the C++ interface.

The following types are implemented as aliases of fundamental and standardized C++ basic types:

CONZEPT 16-TypC++-Typ (Alias)C++-BasistypC++-Standard-Header
alphaC16::Value::Alphastd::string<string>
logicC16::Value::Logicbool-
byte, int8C16::Value::Bytestd::uint8_t<cstdint>
word, int16C16::Value::Wordstd::uint16_t<cstdint>
int, long, int32C16::Value::Intstd::int32_t<cstdint>
bigint, int64C16::Value::Bigintstd::int64_t<cstdint>
floatC16::Value::Floatdouble-

Other supported types that are not based on C++ basic types:

CONZEPT 16-TypC++-Typ
dateC16::Value::Date
timeC16::Value::Time

Classes

Probably the most important class of the C++ interface is C16::Database. It is the starting point for all operations related to a database. For example, it contains functions for determining the name, version and status of the database. It also provides functions for determining data structure elements such as tables, partial data records and fields.

There are also classes for accessing database content, such as data records, texts, procedures, selections and binary objects.

Other classes worth mentioning are C16::Array<Element> and C16::Variant: Class C16::Array represents a sequence of fixed size of type Element. The elements of the array can be changed, but no elements can be deleted or added. Class C16::Variant encapsulates one of several possible alternative contents. It is used when the type of an element is variable, such as with arguments for procedures.

Examples

In the following, an example of an extension and an application will illustrate the use of the C++ interface.

Extension

Function DllCall() is used to call the initial function of the extension from a procedure. The initial function named C16_Entry() has the following signature:

C16::Value::Int C16_Entry
(
C16::Database& database,
C16::Array<C16::Variant>& arguments
)

The calling database (C16::Database) and any supplied arguments (C16::Array<C16::Variant>) are passed to it as arguments. It returns an integer (C16::Value::Int), which can be evaluated as a return from DllCall().

Example of a conzept 16 procedure for ordering array elements:

@A+
@C+

define
{
// Sort elements

sCommandSort : 1
// Mix elements

sCommandShuffle : 2
}

global Data
{
gDll : handle;
}

sub Init
{
VarAllocate(Data);
// Load extension

gDll # DllLoad('ArraySort.dll');
}

sub Term
{
// Unload extension

gDll->DllUnload();
VarFree(Data);
}

sub Sort
(
var vArray : alpha[];
)
{
// Call extension

gDll->DllCall(sCommandSort, var vArray);
}

sub Shuffle
(
var vArray : alpha[];
)
{
// Call extension

gDll->DllCall(sCommandShuffle, var vArray);
}

Example of a C++ extension for ordering array elements:

#include "C16/C16-Library.hpp"      // All types of C++ interface for extensions
#include <algorithm> // std::sort
#include <random> // std::default_random_engine

using namespace C16;

namespace Command
{
static const Value::Int SORT = 1;
static const Value::Int SHUFFLE = 2;
}


Value::Int C16_Entry
(
Database& database,
Array<Variant>& arguments
)
{
// 1. expect argument as Int
Value::Int command = arguments[0];
// 2. expect argument as an array of character strings
Array<Value::Alpha>& data = arguments[1];

switch (command)
{
// Sort array
case Command::SORT :
{
std::sort(data.begin(), data.end());
break;
}
// Shuffle array
case Command::SHUFFLE :
{
std::shuffle
(
data.begin(), data.end(),
std::default_random_engine(std::random_device()())
);
break;
}
}

return 0;
}

Application

In order for the application to access a database, it requires an object of class C16::Client to access a server that manages databases.

Example of a C++ console application for counting all data records with an even field value:

#include "C16/C16-Application.hpp"    // All types of C++ interface for applications
#include <iostream> // std::cout

using namespace C16;

int main()
{
// Create client
Client client;

// Establish database connection
Database database
(
client,
"my_server", "my_database", "my_user"
);


// Determine table
const Table& table =
database.tables().get("my_table");


// Create data set sorted by 1st key
RecordsKey records(table, 1);

// Determine data set buffer
const Record& record =
records.record();

// Create field buffer
const Record::FieldConstInt field =
record.field_int("my_field");

// Define counter
int count = 0;

// Datensätze iterieren
for
(
Result result = records.read(Place::FIRST);
result < Result::NO_REC;
result = records.read(Place::NEXT)
)
{
// Even field value
if (field % 2 == 0)
// Increment counter
++count;
}

// Output counter to console
std::cout << count << std::endl;
}

Conclusion

The C++ interface provides a further option for the interoperability of conzept 16 with other programming languages. The object orientation and other concepts of C++ facilitate the development of modern programs.

We are currently working on the final details of the C++ interface and are offering you the opportunity to influence the development of the C++ interface. We will inform you about the final release at a later date.

CONZEPT 16 C++ API – Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *

Leave the field below empty!

Get your Trial Version now!

Test yeet free of charge

Deine Trial Version - jetzt anfordern!

Teste yeet - unverbindlich und kostenfrei

IHRE EVALUIERUNGSLIZENZ - JETZT ANFORDERN!

TESTEN SIE DIE CONZEPT 16 VOLLVERSION - UNVERBINDLICH und KOSTENFREI

Subscribe to our newsletter

[cleverreach_signup]
WordPress Cookie Notice by Real Cookie Banner