Repository navigation
C and CPP
The rules of the method stereotypes, the free-function stereotypes, and the class stereotypes hold in C and C++ as in every language of Stereocode. The section Data Members and Calls of the method stereotypes states the conventions by which Stereocode determines the facts of these rules in every language. This page gives the forms that these facts take in C and C++, the built-in lists that Stereocode reads for C and C++, and one labeled example of each stereotype.
- Stereocode reads a C unit as a C++ unit. A C unit thus holds free functions, structs, and unions, which get their stereotypes with the options
-f,-t, and-u. - A method defined outside its class belongs to the class that its qualified name names, such as
Surface::draw. Where the class sits in a namespace, ausing namespacedirective before the definition reaches the class, provided that exactly one class of that name fits. Where every method of that name in the class is static, the definition is a static method, also where its parameter types differ in their text from those of the declaration. - A method that several
#ifalternatives define counts once in the class stereotypes, with the stereotypes of its first definition.
- A method reaches its object through
thisor*this. A name withoutthis->may also name a data member of the class. - A const method changes only
mutabledata members. Such a method is a set when it changes one data member and a command only when it changes more than one data member or the whole object. - Inside a local class,
thisnames the object of that class.this->xthus names the memberxof the local class and counts as a local variable of the enclosing method. A call throughthisis a call on an object other than the object of that method, as is a call without an object of a method that the local class defines.
- A parameter shares its object with the caller when it is a reference, a pointer, or an array to an object that is not const.
- A function pointer, such as
bool (*filter)(int);, declares a data member, a parameter, or a local variable, never a method. - Stereocode resolves an alias of the type of a data member, such as
using ItemPtr = std::unique_ptr<Item>;ortypedef Item* ItemPtr;, to the aliased type. A standard smart pointer, such asstd::unique_ptr<Item>, counts by the typeItemof the object that it manages.
- A call qualified with the name of the own type or of a parent type, such as
Base::draw(), calls a method of the object itself. A member alias of the type or of a parent, such astypedef StaticDialog MyBaseClass;, qualifies such a call as the name of the parent does. A call qualified with the name of any other type remains a call of a free function. - Beyond the two cases of the section Data Members and Calls, a call to the object itself whose method no type of the archive defines reads the object where the call stands in a const method of a type with a parent outside the archive, since a const method changes only
mutabledata members. - A binary operator whose left operand is
*this, such as*this == other, calls the operator function of the type or a free function.<<and>>after a stream or after a variable of a class of the archive are calls on that variable. Each operand that>>extracts into is written, while a shift of a number counts as no call. - A method creates an object with
new, also without an argument list, as innew Matrix.std::make_uniqueandstd::make_sharedcount asnew.
Stereocode reads four built-in lists for C and C++. The list files of the options -p, -c, -s, and -q add entries to these lists under the section [C++], as the README states. Each list below opens with a click.
Primitive types (36 entries)
A type of this list makes no method a collaborator and no return type of a factory.
bool, byte, char, char16_t, char32_t, char8_t, double, float, int, int16_t, int32_t, int64_t, int8_t, long, longdouble, longint, longlong, longlongint, ptrdiff_t, short, shortint, size_t, size_type, string, string_view, u16string, u32string, u8string, uint16_t, uint32_t, uint64_t, uint8_t, void, wchar_t, wstring, wstring_view
Ignored calls (3 entries)
The rules ignore a call of these names, also after a qualifier, as std::exit for exit.
abort, assert, exit
Specifiers and containers (58 entries)
Stereocode strips these entries from a written type before it reads the names of the type. A container counts by the types of its elements. Each entry is a regular expression, such as \.\.\. for ....
&, &&, ::const_iterator, ::iterator, <, >, \*, __cdecl, __clrcall, __fastcall, __stdcall, __thiscall, __vectorcall, _Noreturn, _Thread_local, APIENTRY, array, CALLBACK, const, constexpr, deque, explicit, extern, forward_list, friend, inline, list, map, multimap, multiset, mutable, pair, PASCAL, priority_queue, private, protected, public, queue, register, restrict, set, signed, span, stack, static, STDAPICALLTYPE, STDMETHODCALLTYPE, thread_local, unordered_map, unordered_multimap, unordered_multiset, unordered_set, unsigned, vector, virtual, volatile, WINAPI, WINAPIV
Query methods (7 entries)
A call of these methods only reads the variable that the call is on.
c_str, capacity, count, empty, length, max_size, size
Each example below is the declaration of an element from the stereotype cases of Stereocode, whose expected stereotypes are written by hand in @stereotype comments. Each link opens the case on the branch develop. The second column gives every stereotype of the element. A stereotype without an example has no case in C and C++.
TABLE 1. Examples of the method stereotypes in C and C++.
| Stereotype | Stereotypes of the element | Declaration |
|---|---|---|
| main | main |
int main(void) { bump(); show(twice(zero())); return 0; } |
| predicate | predicate |
bool isEven(int value) { return value % 2 == 0; } |
| property | property |
int square(int value) { return value * value; } |
| global-command | global-command |
void addCalls(int count) { g_calls += count; } |
| command | command |
void set_x(struct point* p, int x) { p->x = x; } |
| factory | property factory |
Widget* makeWidget(int style) { Widget* widget = new Widget(style); return wi... |
| literal | literal |
static int zero(void) { return 0; } |
| wrapper | wrapper |
void resetCopy(Widget widget) { widget.reset(); } |
| empty | empty |
void noop(int value) { } |
| unclassified | unclassified |
static int madeInClass() { return s_made; } |
TABLE 2. Examples of the free-function stereotypes in C and C++, which the option -f assigns.
| Stereotype | Stereotypes of the element | Declaration |
|---|---|---|
| boundary | boundary |
class Exporter |
| commander | commander data-class small-class |
class Leaf : public Mid { public: |
| controller | controller |
class Spooler |
| data-class | data-class |
class Point |
| data-provider | data-provider |
class Circle |
| data-struct | data-provider data-struct small-struct |
struct Size { int width; |
| data-union | data-provider data-union small-union |
typedef union |
| degenerate | factory controller lazy-class degenerate |
class Factory100 |
| empty | empty |
union value { int i; float f; }; |
| entity | entity |
class Surface |
| factory | factory controller |
class WidgetFactory |
| large-class | large-class |
class Box |
| large-struct | large-struct |
struct Frame |
| large-union | large-union |
union Cell |
| lazy-class | lazy-class |
class Settings |
| lazy-struct | lazy-struct |
struct Slot |
| lazy-union | lazy-union |
union Bits |
| minimal-entity | minimal-entity |
class Point |
| pure-controller | pure-controller |
class Dispatcher |
| small-class | small-class |
class Counter |
| small-struct | data-provider small-struct |
struct Pixel : public Point |
| small-union | data-provider data-union small-union |
typedef union |
| unclassified | unclassified |
class Large22 |
TABLE 3. Examples of the class stereotypes in C and C++, where large-class, lazy-class, data-class, and small-class of a type of another kind take that kind in place of class, such as data-struct.