xtd - Reference Guide  0.2.0
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 abstract_   : public abstract_object
 This keyword is used to represents an abstract class. More...
 
#define abstract_object_   : xtd::abstract_object
 This keyword is used to represents an abstract class. More...
 
#define block_scope_(...)
 The specified expression is cleared automatically when the scope is ended. More...
 
#define csf_   current_stack_frame_
 Provides information about the current stack frame. More...
 
#define current_stack_frame_   xtd::diagnostics::stack_frame {__FILE__, __LINE__, __func__}
 Provides information about the current stack frame. More...
 
#define interface_   : public xtd::interface
 This keyword is use to represent an interface. More...
 
#define nameof_(...)   std::string(#__VA_ARGS__)
 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_   : xtd::static_object
 This keyword is use to represent a static object. A static object can't be instantiated (constructors are deleted). More...
 
#define static_object_   : xtd::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_(...)   system_exception(add_current_stack_frame_(__VA_ARGS__))
 Helper on system_exception to call it with caller information. More...
 
#define typeof_   xtd::__s__::__typeof_
 Used to obtain the type string for a type. A typeof_ expression takes the following form: More...
 
#define unused_   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

◆ abstract_

#define abstract_   : public abstract_object

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

This keyword is used to represents an abstract class.

Namespace
xtd
Library
xtd.core
Remarks
This keyword has no other use than to tag a class to abstract.
Examples
class foo abstract_ {
public:
virtual std::string to_string() = 0;
};

◆ abstract_object_

#define abstract_object_   : xtd::abstract_object

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

This keyword is used to represents an abstract class.

Namespace
xtd
Library
xtd.core
Remarks
This keyword has no other use than to tag a class to abstract.
Examples
class foo abstract_object_ {
public:
virtual std::string to_string() = 0;
};

◆ block_scope_

#define block_scope_ (   ...)

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

Value:
for (bool __xtd_block_scope__ = true; __xtd_block_scope__; __xtd_block_scope__ = false)\
for (__VA_ARGS__; __xtd_block_scope__; __xtd_block_scope__ = false)

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;
}
Remarks
same as using_

◆ csf_

#define csf_   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 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
Remarks
same as current_stack_frame_

◆ current_stack_frame_

#define current_stack_frame_   xtd::diagnostics::stack_frame {__FILE__, __LINE__, __func__}

#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
Remarks
same as csf_
Examples:
application_and_exception.cpp, exception_box.cpp, and exception_dialog.cpp.

◆ interface_

#define interface_   : public xtd::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";}
};

◆ nameof_

#define nameof_ (   ...)    std::string(#__VA_ARGS__)

#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()"
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");
}
}

◆ startup_

#define startup_ (   main_class)

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

Value:
int main(int argc, char* argv[]) {\
try {\
struct startup final static_ {\
static int run(void (*main_function)(), int, char*[]) {main_function(); return xtd::environment::exit_code();}\
static int run(int (*main_function)(), int, char*[]) {return main_function();}\
static int run(void (*main_function)(int argc, char* argv[]), int argc, char* argv[]) {main_function(argc, argv); return xtd::environment::exit_code();}\
static int run(void (*main_function)(xtd::collections::specialized::string_vector), int argc, char* argv[]) {main_function({argv + 1, argv + argc}); return xtd::environment::exit_code();}\
static int run(void (*main_function)(const xtd::collections::specialized::string_vector&), int argc, char* argv[]) {main_function({argv + 1, argv + argc}); return xtd::environment::exit_code();}\
static int run(int (*main_function)(int argc, char* argv[]), int argc, char* argv[]) {return main_function(argc, argv);}\
static int run(int (*main_function)(xtd::collections::specialized::string_vector), int argc, char* argv[]) {return main_function({argv + 1, argv + argc});}\
static int run(int (*main_function)(const xtd::collections::specialized::string_vector&), int argc, char* argv[]) {return main_function({argv + 1, argv + argc});}\
};\
return startup::run(main_class::main, argc, argv);\
} catch(const xtd::system_exception& e) {\
__startup_catch_exception__(e);\
} catch(const std::exception& e) {\
__startup_catch_exception__(e);\
} catch(...) {\
__startup_catch_exception__();\
}\
}\
int __startup_force_to_end_with_semicolon__ = 0
Defines the base class for predefined exceptions in the xtd namespace.
Definition: system_exception.h:24
static int exit_code()
Gets the exit code of the process.
#define static_
This keyword is use to represent a static object. A static object can&#39;t be instantiated (constructors...
Definition: static.h:38
std::vector< xtd::ustring > string_vector
Represents a collection of strings.
Definition: string_vector.h:20

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
// 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
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
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_   : xtd::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_ {
public:
static std::string to_string() {return "foo";}
};

◆ static_object_

#define static_object_   : xtd::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";}
};

◆ system_exception_

#define system_exception_ (   ...)    system_exception(add_current_stack_frame_(__VA_ARGS__))

#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_)
...
}

◆ typeof_

#define typeof_   xtd::__s__::__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);
Remarks
The typeof_ operator cannot be overloaded.

◆ unused_

#define unused_   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>

Value:
for (bool __xtd_using__ = true; __xtd_using__; __xtd_using__ = false)\
for (__VA_ARGS__; __xtd_using__; __xtd_using__ = false)

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;
}
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_