xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
xtd - Reference Guide Documentation

Modern c++17/20 framework to create console, forms (GUI like WinForms) and unit test applications on Windows, macOS, Linux, iOS and android.

Features

  • a collection of native C++ classes libraries, to complete std;
  • API close to the .net API with a modern C++ approach and full integration with the std standard;
  • written in efficient, modern C++17 / C++20 with RAII programming idiom;
  • and highly portable and available on many different platforms (Windows, macOS, Linux, iOS and android);

For more information see:

Examples

The classic first application 'Hello World'.

Console

hello_world_console.cpp:

#include <xtd/xtd>
using namespace xtd;
int main() {
console::background_color(console_color::blue);
console::foreground_color(console_color::white);
console::write_line("Hello, World!");
}
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(hello_world_console)
find_package(xtd REQUIRED)
add_sources(hello_world_console.cpp)
target_type(CONSOLE_APPLICATION)

Build and run

Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:

xtdc run

Output

Hello, World!

Forms

hello_world_forms.cpp:

#include <xtd/xtd>
using namespace xtd::forms;
class main_form : public form {
public:
main_form() {
text("Hello world (message_box)");
button1.location({10, 10});
button1.parent(*this);
button1.text("&Click me");
button1.click += [] {
message_box::show("Hello, World!");
};
}
private:
};
int main() {
application::run(main_form());
}
Represents a Windows button control.
Definition: button.h:54
Represents a window or dialog box that makes up an application's user interface.
Definition: form.h:40
@ button1
The first button on the message box is the default button.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(hello_world_forms)
find_package(xtd REQUIRED)
add_sources(hello_world_forms.cpp)
target_type(GUI_APPLICATION)

Build and run

Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:

xtdc run

Output

Windows:


macOS:


Linux Gnome:


Unit tests

hello_world_test.cpp:

#include <xtd/xtd>
#include <string>
using namespace std;
using namespace xtd::tunit;
namespace unit_tests {
class test_class_(hello_world_test) {
public:
void test_method_(create_string_from_literal) {
string s = "Hello, World!";
assert::are_equal("Hello, World!", s);
}
void test_method_(create_string_from_chars) {
string s = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
valid::are_equal(13, s.size());
string_assert::starts_with("Hello,", s);
string_assert::ends_with(" World!", s);
}
};
}
int main() {
return console_unit_test(argv, argc).run();
}
The console_unit_test class is console unit test interface.
Definition: console_unit_test.h:23
int run()
Runs all tests in this UnitTest object and prints the result.
Definition: unit_test.h:44
@ s
The S key.
The tunit namespace contains a unit test library.
Definition: abort_error.h:11

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(hello_world_test)
find_package(xtd REQUIRED)
add_sources(hello_world_test.cpp)
target_type(TEST_APPLICATION)

Build and run

Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:

xtdc run

Output

Start 2 tests from 1 test case
Run tests:
SUCCEED hello_world_test.create_string_from_literal (0 ms total)
SUCCEED hello_world_test.create_string_from_chars (0 ms total)
Test results:
SUCCEED 2 tests.
End 2 tests from 1 test case ran. (0 ms total)
Definition: test.h:24

Getting Started

  • Installation provides download and install documentation.
  • Portability provides information about C++, libraries dependency, Operating System supported, Compilers and Development Environment tools..
  • Examples provides some examples.