xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Macros
keywords

Definition

Keywords are predefined, reserved identifiers that have special meanings to the compiler.

Macros

#define block_scope_(...)
 The specified expression is cleared automatically when the scope is ended. More...
 
#define core_export_
 Define shared library export. More...
 
#define csf_
 Provides information about the current stack frame. More...
 
#define current_stack_frame_
 Provides information about the current stack frame. More...
 
#define drawing_export_
 Define shared library export. More...
 
#define export_
 Define shared library export. More...
 
#define forms_export_
 Define shared library export. More...
 
#define interface_
 This keyword is use to represent an interface. More...
 
#define nameof_(...)
 Used to obtain the simple (unqualified) string name of a variable, type, or member. More...
 
#define startup_(main_class)
 Defines the entry point to be called when the application loads. Generally this is set either to the main form in your application or to the main procedure that should run when the application starts. More...
 
#define static_
 This keyword is use to represent a static object. A static object can't be instantiated (constructors are deleted). More...
 
#define static_object_
 This keyword is use to represent a static object. A static object can't be instantiated (constructors are deleted). More...
 
#define system_exception_(...)
 Helper on system_exception to call it with caller information. More...
 
#define tunit_export_
 Define shared library export. More...
 
#define typeof_
 Used to obtain the type string for a type. A typeof_ expression takes the following form: More...
 
#define unused_
 It may be used to suppress the "unused variable" or "unused local typedefs" compiler warnings when the variable or typedef can't be removed or commented out, e.g. when some blocks of the code are conditionally activated. More...
 
#define using_(...)
 The specified expression is cleared automatically when the scope is ended. More...
 

Macro Definition Documentation

◆ block_scope_

#define block_scope_ (   ...)

#include <xtd.core/include/xtd/block_scope.h>

The specified expression is cleared automatically when the scope is ended.

Namespace
xtd
Library
xtd.core
Examples
// values is released automatically after the end closure }.
block_scope_(auto values = {1, 2, 3, 4, 5}) {
cout << ustring::join(", ", values) << endl;
}
#define block_scope_(...)
The specified expression is cleared automatically when the scope is ended.
Definition: block_scope.h:22
Remarks
same as using_

◆ core_export_

#define core_export_

#include <xtd.core/include/xtd/core_export.h>

Define shared library export.

Warning
Internal use only

◆ csf_

#define csf_

#include <xtd.core/include/xtd/diagnostics/stack_frame.h>

Provides information about the current stack frame.

Library
xtd.core
Returns
Informations about the current stack frame.
Examples
The following example shows how to use the csf_.
#include <xtd/xtd>
using namespace std;
using namespace xtd;
void trace_message(const ustring& message, const xtd::diagnostics::stack_frame& stack_frame) {
console::write_line("stack_frame: {}\n", stack_frame);
console::write_line("Message: {}", message);
console::write_line("Method: {}", stack_frame.get_method());
console::write_line("File name: {}", stack_frame.get_file_name());
console::write_line("File line number: {}", stack_frame.get_file_line_number());
}
int main() {
trace_message("Something has happened.", csf_);
// trace_message("Something has happened.", csf_); is same as :
//
// trace_message("Something has happened.", {__FILE__, __LINE__, __func__});
}
// This code can produce the following output:
//
// stack_frame: /!---OMITTED---!/csf.cpp:15:0
//
// Message: Something happened.
// Method name: main
// File name: /!---OMITTED---!/current_stack_trace.cpp
// File line number: 15
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:29
virtual const xtd::ustring & get_file_name() const
Gets the file name that contains the code that is executing. This information is typically extracted ...
virtual uint32_t get_file_line_number() const
Gets the line number in the file that contains the code that is executing. This information is typica...
virtual const xtd::ustring & get_method() const
Gets the method in which the frame is executing.
#define csf_
Provides information about the current stack frame.
Definition: stack_frame.h:213
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Remarks
same as current_stack_frame_

◆ current_stack_frame_

#define current_stack_frame_

#include <xtd.core/include/xtd/diagnostics/stack_frame.h>

Provides information about the current stack frame.

Library
xtd.core
Returns
Informations about the current stack frame.
Examples
The following example shows how to use the current_stack_frame_.
#include <xtd/xtd>
using namespace std;
using namespace xtd;
void trace_message(const ustring& message, const xtd::diagnostics::stack_frame& stack_frame) {
console::write_line("stack_frame: {}\n", stack_frame);
console::write_line("Message: {}", message);
console::write_line("Method: {}", stack_frame.get_method());
console::write_line("File name: {}", stack_frame.get_file_name());
console::write_line("File line number: {}", stack_frame.get_file_line_number());
}
int main() {
trace_message("Something has happened.", current_stack_frame_);
// trace_message("Something has happened.", current_stack_frame_); is same as :
//
// trace_message("Something has happened.", {__FILE__, __LINE__, __func__});
}
// This code can produce the following output:
//
// stack_frame: /!---OMITTED---!/current_stack_frame.cpp:15:0
//
// Message: Something happened.
// Method name: main
// File name: /!---OMITTED---!/current_stack_trace.cpp
// File line number: 15
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
Remarks
same as csf_
Examples
application_and_exception.cpp, exception_box.cpp, and exception_dialog.cpp.

◆ drawing_export_

#define drawing_export_

#include <xtd.drawing/include/xtd/drawing_export.h>

Define shared library export.

Warning
Internal use only

◆ export_

#define export_

#include <xtd/include/xtd/export.h>

Define shared library export.

Warning
Internal use only

◆ forms_export_

#define forms_export_

#include <xtd.forms/include/xtd/forms_export.h>

Define shared library export.

Warning
Internal use only

◆ interface_

#define interface_

#include <xtd.core/include/xtd/interface.h>

This keyword is use to represent an interface.

Library
xtd.core
Examples
class istringable interface_ {
public:
virtual std::string to_string() const = 0;
};
class foo : public istringable {
public:
Foo() = default;
std:::string to_string() const override {return "foo";}
};
#define interface_
This keyword is use to represent an interface.
Definition: interface.h:55
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37

◆ nameof_

#define nameof_ (   ...)

#include <xtd.core/include/xtd/nameof.h>

Used to obtain the simple (unqualified) string name of a variable, type, or member.

Namespace
xtd
Library
xtd.core

When reporting errors in code, hooking up model-view-controller (MVC) links, firing property changed events, etc., you often want to capture the string name of a method. Using nameof helps keep your code valid when renaming definitions. Before, you had to use string literals to refer to definitions, which is brittle when renaming code elements because tools do not know to check these string literals.

A nameof expression has this form:

if (x == null) throw std::argument_error(nameof_(x));
write_line(nameof_(person.address().zip_code())); // prints "person.address().zip_code()"
#define nameof_(...)
Used to obtain the simple (unqualified) string name of a variable, type, or member.
Definition: nameof.h:34
Examples
Some C++ examples:
Remarks
The argument to nameof must be a simple name, qualified name, member access, base access with a specified member, or this access with a specified member. The argument expression identifies a code definition, but it is never evaluated.
Because the argument needs to be an expression syntactically, there are many things disallowed that are not useful to list. The following are worth mentioning that produce errors: predefined types (for example, int or void), nullable types (Point?), array types (Customer[,]), pointer types (Buffer*), qualified alias (A::B), and unbound generic types (Dictionary<,>), preprocessing symbols (DEBUG), and labels (loop:).
If you need to get the fully-qualified name, you can use the typeof_ expression along with nameof. For example:
class c {
public_ void f(int i) {
log(xtd::ustring::format("{0}.{1}", typeof_(C), nameof_(f)), "method entry");
}
}
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
#define typeof_
Used to obtain the type string for a type. A typeof_ expression takes the following form:
Definition: typeof.h:37
@ c
The C key.
@ f
The F key.

◆ startup_

#define startup_ (   main_class)

#include <xtd.core/include/xtd/startup.h>

Defines the entry point to be called when the application loads. Generally this is set either to the main form in your application or to the main procedure that should run when the application starts.

Namespace
xtd
Library
xtd.core
Parameters
main_classThe class that contains the static main method.
Examples
This example show a main method without arguments and without return code
#include <xtd/xtd>
using namespace xtd;
namespace examples {
class program {
public:
static void main() {
// Write arguments to the console output
for (ustring arg : environment::get_command_line_args())
// return 42
}
};
}
startup_(examples::program);
// startup_(examples::program); is same as :
//
// int main(int argc, char* argv[]) {
// examples::program::main();
// return environment::exit_code();
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// /!---OMITTED---!/main1
// one
// two
// three four
// five
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static xtd::collections::specialized::string_vector get_command_line_args()
Returns a string array containing the command-line arguments for the current process.
static int exit_code()
Gets the exit code of the process.
#define startup_(main_class)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition: startup.h:49
This example show a main method with a return code and without arguments
#include <xtd/xtd>
using namespace xtd;
namespace examples {
class program {
public:
static int main() {
// Write arguments to the console output
for (ustring arg : environment::get_command_line_args())
return 42;
}
};
}
startup_(examples::program);
// startup_(examples::program); is same as :
//
// int main(int argc, char* argv[]) {
// return examples::program::main();
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// /!---OMITTED---!/main2
// one
// two
// three four
// five
This example show a main method with argument and without return code
#include <xtd/xtd>
using namespace std;
using namespace xtd;
namespace examples {
class program {
public:
static void main(const vector<ustring>& args) {
// Write arguments to the console output
for (ustring arg : args)
console::write_line(arg);
// return 42
environment::exit_code(42);
}
};
}
startup_(examples::program);
// startup_(examples::program); is same as :
//
// int main(int argc, char* argv[]) {
// examples::program::main({argv + 1, argv + argc});
// return environment::exit_code();
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// one
// two
// three four
// five
This example show a main method with argument and return code
#include <xtd/xtd>
using namespace std;
using namespace xtd;
namespace examples {
class program {
public:
static int main(const vector<ustring>& args) {
// Write arguments to the console output
for (ustring arg : args)
console::write_line(arg);
return 42;
}
};
}
startup_(examples::program);
// startup_(examples::program); is same as :
//
// int main(int argc, char* argv[]) {
// return examples::program::main({argv + 1, argv + argc});
// }
// This code produces the following output if one two "three four" five are entered on command line:
//
// one
// two
// three four
// five
Examples
application_and_exception.cpp, and countries.cpp.

◆ static_

#define static_

#include <xtd.core/include/xtd/static.h>

This keyword is use to represent a static object. A static object can't be instantiated (constructors are deleted).

Namespace
xtd
Library
xtd.core
Examples
class foo static_ {
public:
static std::string to_string() {return "foo";}
};
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition: static.h:38

◆ static_object_

#define static_object_

#include <xtd.core/include/xtd/static.h>

This keyword is use to represent a static object. A static object can't be instantiated (constructors are deleted).

Namespace
xtd
Library
xtd.core
Examples
class foo static_object_ {
public:
static std::string to_string() {return "foo";}
};
#define static_object_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition: static.h:54

◆ system_exception_

#define system_exception_ (   ...)

#include <xtd.core/include/xtd/system_exception.h>

Helper on system_exception to call it with caller information.

Library
xtd.core
Remarks
Is equivalent to system_exception({any argument}, current_stack_frame_)
void my_func() {
if (invalid_info) throw system_exception_(); // same as : throw system_exception(current_stack_frame_)
if (invalid_value) throw system_exception_("Bad value"); // same as : throw system_exception("Bad value", current_stack_frame_)
...
}
#define system_exception_(...)
Helper on system_exception to call it with caller information.
Definition: system_exception.h:170

◆ tunit_export_

#define tunit_export_

#include <xtd.tunit/include/xtd/tunit_export.h>

Define shared library export.

Warning
Internal use only

◆ typeof_

#define typeof_

#include <xtd.core/include/xtd/typeof.h>

Used to obtain the type string for a type. A typeof_ expression takes the following form:

Namespace
xtd
Library
xtd.core
Examples
std::string type1 = typeof_<int32_t>();
int32_t i = 42;
std::string type2 = typeof_(i);
@ i
The I key.
Remarks
The typeof_ operator cannot be overloaded.

◆ unused_

#define unused_

#include <xtd.core/include/xtd/unused.h>

It may be used to suppress the "unused variable" or "unused local typedefs" compiler warnings when the variable or typedef can't be removed or commented out, e.g. when some blocks of the code are conditionally activated.

Namespace
xtd
Library
xtd_core
Parameters
argsvariables to suppress the unused warning
Examples
This example sho how to use Unused():

◆ using_

#define using_ (   ...)

#include <xtd.core/include/xtd/using.h>

The specified expression is cleared automatically when the scope is ended.

Namespace
xtd
Library
xtd.core
Examples
// values is released automatically after the end closure }.
using_(auto values = {1, 2, 3, 4, 5}) {
cout << ustring::join(", ", values) << endl;
}
#define using_(...)
The specified expression is cleared automatically when the scope is ended.
Definition: using.h:34
same as :
using_(auto values = {1, 2, 3, 4, 5})
cout << ustring::join(", ", values) << endl;
same as :
{
auto values = {1, 2, 3, 4, 5};
cout << ustring::join(", ", values) << endl;
}
Remarks
same as block_scope_