From 0a5dc51fc2e2e704bea9dbde9f1c069cd2580c27 Mon Sep 17 00:00:00 2001 From: "Frank B. Brokken" Date: Sat, 2 Dec 2017 13:43:03 +0100 Subject: [PATCH] completed the system_error description in advancedtemplates --- .../yo/advancedtemplates/errorcategory.yo | 20 ++-- annotations/yo/advancedtemplates/errorcode.yo | 6 +- .../yo/advancedtemplates/errorcondition.yo | 100 ++++++++++-------- .../examples/errcode.1/CLASSES | 3 + .../calculatorerror/calculatorerror.h | 22 ++-- .../calculatorerror/calculatorerror.ih | 0 .../calculatorerror/data.cc | 0 .../calculatorerror/frame | 0 .../calculatorerror/makeerrorcode.cc | 0 .../calculatorerror/message.cc | 0 .../calculatorerror/name.cc | 0 .../errorsource/data.cc | 0 .../errorsource/equivalent.cc | 0 .../errorsource/errorsource.h | 0 .../errorsource/errorsource.ih | 0 .../{errcode => errcode.1}/errorsource/frame | 0 .../errorsource/makeerrorcondition.cc | 0 .../errorsource/message.cc | 0 .../errorsource/name.cc | 0 .../examples/{errcode2 => errcode.1}/frame | 0 .../examples/{errcode2 => errcode.1}/icmconf | 1 - .../examples/errcode.1/main.cc | 19 ++++ .../examples/errcode.1/main.ih | 11 ++ .../simulatorerror/data.cc | 0 .../simulatorerror/frame | 0 .../simulatorerror/makeerrorcode.cc | 0 .../simulatorerror/message.cc | 0 .../simulatorerror/name.cc | 0 .../simulatorerror/simulatorerror.h | 12 ++- .../simulatorerror/simulatorerror.ih | 0 .../examples/errcode/CLASSES | 11 +- .../calculatorcategory/calculatorcategory.h | 0 .../calculatorcategory/calculatorcategory.ih | 0 .../calculatorcategory/data.cc | 0 .../calculatorcategory/frame | 0 .../calculatorcategory/instance.cc | 0 .../calculatorcategory/makeerrorcode.cc | 0 .../calculatorcategory/message.cc | 0 .../calculatorcategory/name.cc | 0 .../errcode/calculatorerror/calculatorerror.h | 22 ++-- .../categorybase/categorybase.h | 0 .../{errcode2 => errcode}/catmap/catmap.h | 0 .../conditioncategory/conditioncategory.h | 10 +- .../conditioncategory/conditioncategory.ih | 0 .../conditioncategory/conditioncategory1.cc | 0 .../conditioncategory/data.cc | 0 .../conditioncategory/equivalent.cc | 3 +- .../conditioncategory/frame | 0 .../conditioncategory/instance.cc | 0 .../conditioncategory/message.cc | 0 .../conditioncategory/name.cc | 0 .../errorcondition/addcondition.cc | 0 .../errorcondition/data.cc | 0 .../errorcondition/errorcondition.h | 5 +- .../errorcondition/errorcondition.ih | 0 .../errorcondition/errorcondition1.cc | 0 .../errorcondition/frame | 0 .../errorcondition/functor.cc | 0 .../errorcondition/instance.cc | 0 .../errorcondition/makeerrrorcondition.cc | 2 +- .../examples/errcode/icmconf | 3 +- .../examples/errcode/main.cc | 48 +++++++-- .../examples/errcode/main.ih | 14 ++- .../{errcode2 => errcode}/part/main.cc | 8 +- .../simulatorcategory/data.cc | 0 .../simulatorcategory/frame | 0 .../simulatorcategory/instance.cc | 0 .../simulatorcategory/makeerrorcode.cc | 0 .../simulatorcategory/message.cc | 0 .../simulatorcategory/name.cc | 0 .../simulatorcategory/simulatorcategory.h | 0 .../simulatorcategory/simulatorcategory.ih | 0 .../errcode/simulatorerror/simulatorerror.h | 12 +-- .../examples/errcode2/CLASSES | 8 -- .../examples/errcode2/main.cc | 47 -------- .../examples/errcode2/main.ih | 15 --- 76 files changed, 213 insertions(+), 189 deletions(-) create mode 100644 annotations/yo/advancedtemplates/examples/errcode.1/CLASSES rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode.1}/calculatorerror/calculatorerror.h (71%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/calculatorerror/calculatorerror.ih (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/calculatorerror/data.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/calculatorerror/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/calculatorerror/makeerrorcode.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/calculatorerror/message.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/calculatorerror/name.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/data.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/equivalent.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/errorsource.h (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/errorsource.ih (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/makeerrorcondition.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/message.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/errorsource/name.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode.1}/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode.1}/icmconf (93%) create mode 100644 annotations/yo/advancedtemplates/examples/errcode.1/main.cc create mode 100644 annotations/yo/advancedtemplates/examples/errcode.1/main.ih rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/simulatorerror/data.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/simulatorerror/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/simulatorerror/makeerrorcode.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/simulatorerror/message.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/simulatorerror/name.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode.1}/simulatorerror/simulatorerror.h (68%) rename annotations/yo/advancedtemplates/examples/{errcode => errcode.1}/simulatorerror/simulatorerror.ih (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/calculatorcategory.h (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/calculatorcategory.ih (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/data.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/instance.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/makeerrorcode.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/message.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/calculatorcategory/name.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/categorybase/categorybase.h (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/catmap/catmap.h (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/conditioncategory.h (85%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/conditioncategory.ih (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/conditioncategory1.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/data.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/equivalent.cc (97%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/instance.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/message.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/conditioncategory/name.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/addcondition.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/data.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/errorcondition.h (93%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/errorcondition.ih (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/errorcondition1.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/functor.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/instance.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/errorcondition/makeerrrorcondition.cc (59%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/part/main.cc (61%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/data.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/frame (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/instance.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/makeerrorcode.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/message.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/name.cc (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/simulatorcategory.h (100%) rename annotations/yo/advancedtemplates/examples/{errcode2 => errcode}/simulatorcategory/simulatorcategory.ih (100%) delete mode 100644 annotations/yo/advancedtemplates/examples/errcode2/CLASSES delete mode 100644 annotations/yo/advancedtemplates/examples/errcode2/main.cc delete mode 100644 annotations/yo/advancedtemplates/examples/errcode2/main.ih diff --git a/annotations/yo/advancedtemplates/errorcategory.yo b/annotations/yo/advancedtemplates/errorcategory.yo index 4a2f94d2..ecea1e75 100644 --- a/annotations/yo/advancedtemplates/errorcategory.yo +++ b/annotations/yo/advancedtemplates/errorcategory.yo @@ -15,7 +15,7 @@ associations are collected in a class template tt(CatMap), derived from tt(std::unordered_map). tt(CatMap)'s design is a rather straightforward, offering a constructor accepting an tt(std::initializer_list): - verbinsert(-s4 //impl examples/errcode2/catmap/catmap.h) + verbinsert(-s4 //impl examples/errcode/catmap/catmap.h) As tt(ErrorCodeEnum)-values may have been randomly assigned (not using 0) tt(CapMap) objects offers fast access to the errors' descriptions and @@ -40,7 +40,7 @@ const) member, returning the description matching tt(ev) or the error message tt(noEnumValue) if tt(ev) does not represent a defined enum value. Here is its implementation: - verbinsert(-s4 //msg examples/errcode2/categorybase/categorybase.h) + verbinsert(-s4 //msg examples/errcode/categorybase/categorybase.h) But that isn't all that tt(CategoryBase) can accomplish: since it contains tt(s_errors), the associations between error enum values and category @@ -59,7 +59,7 @@ tt(s_errors), and compares the stored error condition's name to the name provided by the (singleton) tt(error_condition) object, given the condition's number. Here is its implementation: - verbinsert(-s4 //equiv examples/errcode2/categorybase/categorybase.h) + verbinsert(-s4 //equiv examples/errcode/categorybase/categorybase.h) In addition, to allow single inheritance to be used when deriving classes from tt(std::error_category) the class tt(CategoryBase) itself is derived from @@ -71,7 +71,7 @@ tt(equivalent) that can be used by all classes derived from tt(std::error_category); and, finally, a class that itself also is an tt(error_category) class. Here is the interface of tt(CategoryBase): - verbinsert(-s4 //impl examples/errcode2/categorybase/categorybase.h) + verbinsert(-s4 //impl examples/errcode/categorybase/categorybase.h) Now we're ready for defining our own error category classes. To define a category class we take the following steps: @@ -86,12 +86,12 @@ category class we take the following steps: tt(CalculatorCategory's) class interface: verbinsert(//class - examples/errcode2/calculatorcategory/calculatorcategory.h) + examples/errcode/calculatorcategory/calculatorcategory.h) The member tt(instance) returns a reference to the singleton object, initializing it the first time it is called: - verbinsert(//impl examples/errcode2/calculatorcategory/instance.cc) + verbinsert(//impl examples/errcode/calculatorcategory/instance.cc) it() The member tt(name) simply returns a short string naming the category (tt("calculator") for the calculator category). @@ -100,7 +100,7 @@ category class we take the following steps: thanks to tt(CategoryBase::member): it merely returns what's returned by that latter member: - verbinsert(//impl examples/errcode2/calculatorcategory/messace.cc) + verbinsert(//impl examples/errcode/calculatorcategory/messace.cc) it() The associations between error code enum values, descriptions and error condition names are defined when initializing the tt(CatMap) @@ -108,20 +108,20 @@ category class we take the following steps: base class it can be initialized when defining the category class. Here is the initialization for tt(CalculatorCategory): - verbinsert(//impl examples/errcode2/calculatorcategory/data.cc) + verbinsert(//impl examples/errcode/calculatorcategory/data.cc) it() We're now in position to actually create tt(error_code) objects from tt(CalculatorError) enum values. For this we define the free function tt(make_error_code(CalculatorError ce)): - verbinsert(//impl examples/errcode2/calculatorcategory/makeerrorcode.cc) + verbinsert(//impl examples/errcode/calculatorcategory/makeerrorcode.cc) ) Now that a tt(CalculatorError) value can be converted to an tt(std::error_code) we can use it in our programs. Here is a little demo program illustrating its use: - verbinsert(-as4 examples/errcode2/main.part); + verbinsert(-as4 examples/errcode/main.part); In the next section defining and using error conditions is covered in detail. diff --git a/annotations/yo/advancedtemplates/errorcode.yo b/annotations/yo/advancedtemplates/errorcode.yo index 195c09ad..a67ba07f 100644 --- a/annotations/yo/advancedtemplates/errorcode.yo +++ b/annotations/yo/advancedtemplates/errorcode.yo @@ -44,8 +44,8 @@ itemization( it() Our first step consists of defining our own error enumerations: one related to the calculator and one related to the simulator: - verbinsert(//enum examples/errcode2/calculatorerror/calculatorerror.h) - verbinsert(//enum examples/errcode2/simulatorerror/simulatorerror.h) + verbinsert(//enum examples/errcode/calculatorerror/calculatorerror.h) + verbinsert(//enum examples/errcode/simulatorerror/simulatorerror.h) The class tt(std::error_code) is designed so that two pieces of information (the error value and its category) become available. The @@ -80,7 +80,7 @@ it() Second, our intention is to let tt(error_code) accept Here is the specialization for tt(CalculatorError); the one for tt(SimulatorError) is defined analogously: - verbinsert(//trait examples/errcode2/calculatorerror/.h) + verbinsert(//trait examples/errcode/calculatorerror/.h) This completes the definition of our own error enumerations, which are now `promoted' to tt(ErrorCodeEnums). diff --git a/annotations/yo/advancedtemplates/errorcondition.yo b/annotations/yo/advancedtemplates/errorcondition.yo index 28f3d9a6..f1a10ada 100644 --- a/annotations/yo/advancedtemplates/errorcondition.yo +++ b/annotations/yo/advancedtemplates/errorcondition.yo @@ -32,58 +32,68 @@ instead use verbal labels denoting error conditions. So rather than specifying }; ) textual labels like tt("InputCond", "UnavailCond",) and tt("SystemCond") -could be used. Instead of defining a fixed-size tt(enum class ErrorCondition) -a singleton tt(class ErrorCondition) is defined, guaranteeing the uniqueness -of error conditions which are identified by their textual labels. +could be used. Instead of defining a fixed-size tt(ErrorConditionEnum) a +singleton class tt(ErrorCondition) is used, providing and encapsulating such +an enumeration, at the same time guaranteeing the uniqueness of error +conditions which are identified by textual labels. -Error conditions are obtained from a function tt(make_error_condition), -expecting an tt(ErrorConditionEnum) value as its argument, and using an -tt(std::error_category) that is associated with -the various error condition enum values, much like tt(CalculatorCategory) was -associated with the tt(CalculatorError) enumeration. The tt(std::error_category) +The class tt(ConditionCategory) implements the requirements imposed by the +class tt(std::error_condition), tailored to the error conditions managed by +the class tt(ErrorCondition). Also designed as a singleton, +tt(ConditionCategory) contains a vector whose elements hold names and +descriptions of the various error conditions. In addition to the familiar +members tt(name, message) and tt(equivalent) it offers a member +tt(addCondition). That latter function is used by tt(ErrorCondition) to add +new error conditions to the current set. Here is its interface: + verbinsert(-s4 //class + examples/errcode/conditioncategory/conditioncategory.h) -========================== WIP +The members tt(name) and tt(message) have trivial implementations. The member +tt(equivalent) receives an tt(error_code) object and an error condition enum +value (as an tt(int)). The function must return tt(true) if the provided +tt(error_code) is associated with the provided error condition enum +value. tt(Equivalent) itself doesn't perform those checks. Rather, it +retrieves the tt(error_code's error_category) and uses that object's +tt(equivalent) function to perform the test: + verbinsert(-s4 //impl + examples/errcode/conditioncategory/equivalent.cc) +Next we look at the class tt(ErrorCondition). It contains a +tt(ConditionCategory) object (i.e., em(the) tt(ConditionCategory) object), and +a tt(unsorted_map), mapping condition names to their indices in the +tt(ConditionCategory's) vector. Other than that it's a rather plain class, +offering members to retrieve the enum values of the various error conditions, +and returning conditions' names given their numbers. Error condition enum +values are simply defined as their indices in the tt(ConditionCategory's) +vector, statically cast to the enum tt(ErrorCondition::Enum). +tt(Enum) by itself is defined as mere enumeration name, promoted to an +tt(ErrorConditionEnum) by the tt(std::is_error_condition_enum) trait class +specialization (comparable to what the tt(is_error_code_enum) trait class +accomplished for our enums like tt(CalculatorError)). Here is the +tt(is_error_condition_enum) trait class specialization, followed by +tt(ErrorCondition's) class interface: + verbinsert(-s4 //trait examples/errcode/errorcondition/errorcondition.h) -is provided by an object of the class tt(ErrorCondCat) -. To create an tt(error_condition) an tt(ErrorCondition::Enum) value -is required and the enum's value matching error category. + verbinsert(-s4 //class examples/errcode/errorcondition/errorcondition.h) +Error conditions objects themselves are returned by a function +tt(make_error_condition), expecting an tt(ErrorConditionEnum) value as its +argument, and internally using an tt(std::error_category) that is associated +with the various error condition enum values, much like tt(CalculatorCategory) +was associated with the tt(CalculatorError) enumeration. Since +tt(ConditionCategory) is a singleton, it can directly pass that singleton +object to the tt(std::error_condition) object: + verbinsert(-s4 //make + examples/errcode/errorcondition/makeerrorcondition.cc) +A demo program illustrating some of the facilities of the tt(error_code, +error_category, error_condition) and related classes concludes this +section. The complete implementation of the program is provided in the +annotations()' source archive in the directory +tt(yo/advancedtemplates/examples/errocde). -: their uniqueness can be guaranteed by another class, -tt(ErrorCondition), which is also a singleton. That class defines an empty -tt(enum Enum), which is promoted to an tt(ErrorConditionEnum) by the -tt(std::is_error_condition_enum) trait class specialization: - verbinsert(-s4 //trait examples/errorcondition/errorcondition.h) + verbinsert(-s4 //demo examples/errcode/errcode/main.cc) -Error ondition objects are created by - - The tt(ErrorCondition) singleton also has a member tt(addCondition) -allowing programs to add error conditions by name (and a description). - -To access error condition objects a - - -Let's -define our conditions as: - verbinsert(-s4 //simerrsrc examples/errcodeenum.cc) - This allows us to distinguish errors made by the user, errors from the -calculator, and errors from the simulator. As in the previous section, we'll -`promote' this enum, this time to an ti(ErrorConditionEnum): - verbinsert(-s4 //simcondtrait examples/errcodeenum.cc) - -Now that an error condition enumeration has been defined, error codes can be -mapped to their appropriate error condition values. To do that, a tt(class -ErrorSourceCategory) is derived (again: in the anonymous namespace) from -tt(std::error_category), similarly to what we did before with, e.g., -tt(CalculatorErrCategory): - verbinsert(-s4 //errorourcecat examples/errcodeenum.cc) - - The tt(name) and tt(message) members are defined as before, but in -addition the member tt(equivalent) is defined comparing a received -tt(error_code) to the available tt(SimErrSource) values. The function -tt(equivalent) returns tt(true) if tt(error_code code) can be mapped to tt(int -condition), which in fact is a statically cast tt(SimErrSource) value. For tt( + diff --git a/annotations/yo/advancedtemplates/examples/errcode.1/CLASSES b/annotations/yo/advancedtemplates/examples/errcode.1/CLASSES new file mode 100644 index 00000000..1e039a2d --- /dev/null +++ b/annotations/yo/advancedtemplates/examples/errcode.1/CLASSES @@ -0,0 +1,3 @@ +calculatorerror +simulatorerror +errorsource diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorerror/calculatorerror.h b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/calculatorerror.h similarity index 71% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorerror/calculatorerror.h rename to annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/calculatorerror.h index 224a83bc..f478f581 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/calculatorerror/calculatorerror.h +++ b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/calculatorerror.h @@ -3,7 +3,7 @@ #include -//enum +//calcerrc enum class CalculatorError { // no 0, since that's by convention implies no error @@ -16,19 +16,25 @@ enum class CalculatorError MissingParentheses, // ( and ) don't match }; //= -//trait + +class CalculatorCategory: public std::error_category +{ + char const *name() const noexcept override; + std::string message(int ce) const override; +}; + +extern CalculatorCategory const calculatorCategory; + +std::error_code make_error_code(CalculatorError ce); + +//calctrait namespace std { template <> struct is_error_code_enum: public true_type {}; } + //= #endif - - - - - - diff --git a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/calculatorerror.ih b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/calculatorerror.ih similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/calculatorerror/calculatorerror.ih rename to annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/calculatorerror.ih diff --git a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/data.cc b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/data.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/calculatorerror/data.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/data.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/frame b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/calculatorerror/frame rename to annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/makeerrorcode.cc b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/makeerrorcode.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/calculatorerror/makeerrorcode.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/makeerrorcode.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/message.cc b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/message.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/calculatorerror/message.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/message.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/name.cc b/annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/name.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/calculatorerror/name.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/calculatorerror/name.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/data.cc b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/data.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/data.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/data.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/equivalent.cc b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/equivalent.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/equivalent.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/equivalent.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/errorsource.h b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/errorsource.h similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/errorsource.h rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/errorsource.h diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/errorsource.ih b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/errorsource.ih similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/errorsource.ih rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/errorsource.ih diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/frame b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/frame rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/makeerrorcondition.cc b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/makeerrorcondition.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/makeerrorcondition.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/makeerrorcondition.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/message.cc b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/message.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/message.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/message.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/errorsource/name.cc b/annotations/yo/advancedtemplates/examples/errcode.1/errorsource/name.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/errorsource/name.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/errorsource/name.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/frame b/annotations/yo/advancedtemplates/examples/errcode.1/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/frame rename to annotations/yo/advancedtemplates/examples/errcode.1/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode2/icmconf b/annotations/yo/advancedtemplates/examples/errcode.1/icmconf similarity index 93% rename from annotations/yo/advancedtemplates/examples/errcode2/icmconf rename to annotations/yo/advancedtemplates/examples/errcode.1/icmconf index 1b9ee447..57a495b9 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/icmconf +++ b/annotations/yo/advancedtemplates/examples/errcode.1/icmconf @@ -1,6 +1,5 @@ #define CLS #define MAIN "main.cc" -#define LIBRARY "modules" #define SOURCES "*.cc" #define OBJ_EXT ".o" #define SHAREDREQ "" diff --git a/annotations/yo/advancedtemplates/examples/errcode.1/main.cc b/annotations/yo/advancedtemplates/examples/errcode.1/main.cc new file mode 100644 index 00000000..dc60f12d --- /dev/null +++ b/annotations/yo/advancedtemplates/examples/errcode.1/main.cc @@ -0,0 +1,19 @@ +#include "main.ih" + +int main() +try +{ + std::error_code ec = CalculatorError::TypeError; + assert(ec == ErrorSource::CalcError); + assert(ec != ErrorSource::SimError); + assert(ec != ErrorSource::InputError); + + ec = CalculatorError::ArityError; + std::cout << ec << ' ' << ec.message() << '\n'; + throw std::system_error{ ec, "For demonstration purposes: " }; +} +catch (std::system_error &se) +{ + std::cout << se.what() << ": " << se.code() << '\n'; +} + diff --git a/annotations/yo/advancedtemplates/examples/errcode.1/main.ih b/annotations/yo/advancedtemplates/examples/errcode.1/main.ih new file mode 100644 index 00000000..08482c67 --- /dev/null +++ b/annotations/yo/advancedtemplates/examples/errcode.1/main.ih @@ -0,0 +1,11 @@ +#include +#include +// #include +// // #include +// #include + +#include "calculatorerror/calculatorerror.h" +#include "simulatorerror/simulatorerror.h" + +#include "errorsource/errorsource.h" + diff --git a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/data.cc b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/data.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/simulatorerror/data.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/data.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/frame b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/simulatorerror/frame rename to annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/makeerrorcode.cc b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/makeerrorcode.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/simulatorerror/makeerrorcode.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/makeerrorcode.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/message.cc b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/message.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/simulatorerror/message.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/message.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/name.cc b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/name.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/simulatorerror/name.cc rename to annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/name.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorerror/simulatorerror.h b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/simulatorerror.h similarity index 68% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorerror/simulatorerror.h rename to annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/simulatorerror.h index 50f6c7eb..f9b6c288 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/simulatorerror/simulatorerror.h +++ b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/simulatorerror.h @@ -3,7 +3,7 @@ #include -//enum +//=simerrc enum class SimulatorError { // no 0 @@ -16,6 +16,12 @@ enum class SimulatorError }; //= +class SimulatorCategory: public std::error_category +{ + char const *name() const noexcept override; + std::string message(int ce) const override; +}; + namespace std { template <> @@ -23,6 +29,10 @@ namespace std {}; } +std::error_code make_error_code(SimulatorError ce); + +extern SimulatorCategory const simulatorCategory; + #endif diff --git a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/simulatorerror.ih b/annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/simulatorerror.ih similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode/simulatorerror/simulatorerror.ih rename to annotations/yo/advancedtemplates/examples/errcode.1/simulatorerror/simulatorerror.ih diff --git a/annotations/yo/advancedtemplates/examples/errcode/CLASSES b/annotations/yo/advancedtemplates/examples/errcode/CLASSES index 1e039a2d..9bf48a81 100644 --- a/annotations/yo/advancedtemplates/examples/errcode/CLASSES +++ b/annotations/yo/advancedtemplates/examples/errcode/CLASSES @@ -1,3 +1,8 @@ -calculatorerror -simulatorerror -errorsource + // specific error categories, defined for this program +calculatorcategory +simulatorcategory + + // classes handling all error conditions +conditioncategory +errorcondition + diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/calculatorcategory.h b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/calculatorcategory.h similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/calculatorcategory.h rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/calculatorcategory.h diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/calculatorcategory.ih b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/calculatorcategory.ih similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/calculatorcategory.ih rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/calculatorcategory.ih diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/data.cc b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/data.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/data.cc rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/data.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/frame b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/frame rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/instance.cc b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/instance.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/instance.cc rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/instance.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/makeerrorcode.cc b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/makeerrorcode.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/makeerrorcode.cc rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/makeerrorcode.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/message.cc b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/message.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/message.cc rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/message.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/name.cc b/annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/name.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/calculatorcategory/name.cc rename to annotations/yo/advancedtemplates/examples/errcode/calculatorcategory/name.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/calculatorerror.h b/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/calculatorerror.h index f478f581..224a83bc 100644 --- a/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/calculatorerror.h +++ b/annotations/yo/advancedtemplates/examples/errcode/calculatorerror/calculatorerror.h @@ -3,7 +3,7 @@ #include -//calcerrc +//enum enum class CalculatorError { // no 0, since that's by convention implies no error @@ -16,25 +16,19 @@ enum class CalculatorError MissingParentheses, // ( and ) don't match }; //= - -class CalculatorCategory: public std::error_category -{ - char const *name() const noexcept override; - std::string message(int ce) const override; -}; - -extern CalculatorCategory const calculatorCategory; - -std::error_code make_error_code(CalculatorError ce); - -//calctrait +//trait namespace std { template <> struct is_error_code_enum: public true_type {}; } - //= #endif + + + + + + diff --git a/annotations/yo/advancedtemplates/examples/errcode2/categorybase/categorybase.h b/annotations/yo/advancedtemplates/examples/errcode/categorybase/categorybase.h similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/categorybase/categorybase.h rename to annotations/yo/advancedtemplates/examples/errcode/categorybase/categorybase.h diff --git a/annotations/yo/advancedtemplates/examples/errcode2/catmap/catmap.h b/annotations/yo/advancedtemplates/examples/errcode/catmap/catmap.h similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/catmap/catmap.h rename to annotations/yo/advancedtemplates/examples/errcode/catmap/catmap.h diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/conditioncategory.h b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/conditioncategory.h similarity index 85% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/conditioncategory.h rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/conditioncategory.h index 520bb577..63b03ffc 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/conditioncategory.h +++ b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/conditioncategory.h @@ -6,6 +6,7 @@ #include #include +//class class ConditionCategory: public std::error_category { static ConditionCategory *s_instance; @@ -25,16 +26,18 @@ class ConditionCategory: public std::error_category bool equivalent(std::error_code const &code, int condition) const noexcept override; + // returns condition idx-th name + std::string const &operator[](size_t idx) const; void addCondition(char const *name, char const *description); size_t size() const; - std::string const &operator[](size_t idx) const; private: ConditionCategory(); }; +//= inline void ConditionCategory::addCondition(char const *name, - char const *description) + char const *description) { d_conditionInfo.push_back({ name, description }); } @@ -50,6 +53,3 @@ inline std::string const &ConditionCategory::operator[](size_t idx) const } #endif - - - diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/conditioncategory.ih b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/conditioncategory.ih similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/conditioncategory.ih rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/conditioncategory.ih diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/conditioncategory1.cc b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/conditioncategory1.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/conditioncategory1.cc rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/conditioncategory1.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/data.cc b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/data.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/data.cc rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/data.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/equivalent.cc b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/equivalent.cc similarity index 97% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/equivalent.cc rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/equivalent.cc index 31ffb52d..2d8bc82c 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/equivalent.cc +++ b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/equivalent.cc @@ -5,9 +5,10 @@ // error code and the condition number to verify that the error condition // associated with the error_code matches the condition number. - +//impl bool ConditionCategory::equivalent(std::error_code const &ec, int condNr ) const noexcept { return ec.category().equivalent(ec, condNr); } +//= diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/frame b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/frame rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/instance.cc b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/instance.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/instance.cc rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/instance.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/message.cc b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/message.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/message.cc rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/message.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/name.cc b/annotations/yo/advancedtemplates/examples/errcode/conditioncategory/name.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/conditioncategory/name.cc rename to annotations/yo/advancedtemplates/examples/errcode/conditioncategory/name.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/addcondition.cc b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/addcondition.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/addcondition.cc rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/addcondition.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/data.cc b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/data.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/data.cc rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/data.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/errorcondition.h b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/errorcondition.h similarity index 93% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/errorcondition.h rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/errorcondition.h index 2859cf27..2456cdea 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/errorcondition.h +++ b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/errorcondition.h @@ -5,6 +5,7 @@ #include "../conditioncategory/conditioncategory.h" +//class class ErrorCondition { static ErrorCondition *s_instance; @@ -31,8 +32,10 @@ class ErrorCondition private: ErrorCondition(); // singleton, see instance.cc - friend std::error_condition make_error_condition(Enum ec); }; +//= + +std::error_condition make_error_condition(ErrorCondition::Enum ec); inline std::string const &ErrorCondition::operator[](size_t nr) const { diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/errorcondition.ih b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/errorcondition.ih similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/errorcondition.ih rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/errorcondition.ih diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/errorcondition1.cc b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/errorcondition1.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/errorcondition1.cc rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/errorcondition1.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/frame b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/frame rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/functor.cc b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/functor.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/functor.cc rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/functor.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/instance.cc b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/instance.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/instance.cc rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/instance.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/makeerrrorcondition.cc b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/makeerrrorcondition.cc similarity index 59% rename from annotations/yo/advancedtemplates/examples/errcode2/errorcondition/makeerrrorcondition.cc rename to annotations/yo/advancedtemplates/examples/errcode/errorcondition/makeerrrorcondition.cc index 33c286db..19044874 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/errorcondition/makeerrrorcondition.cc +++ b/annotations/yo/advancedtemplates/examples/errcode/errorcondition/makeerrrorcondition.cc @@ -2,7 +2,7 @@ std::error_condition make_error_condition(ErrorCondition::Enum ec) { - return { static_cast(ec), ErrorCondition::instance().d_ec }; + return { static_cast(ec), ConditionCategory::instance() }; } diff --git a/annotations/yo/advancedtemplates/examples/errcode/icmconf b/annotations/yo/advancedtemplates/examples/errcode/icmconf index 57a495b9..6303082a 100644 --- a/annotations/yo/advancedtemplates/examples/errcode/icmconf +++ b/annotations/yo/advancedtemplates/examples/errcode/icmconf @@ -1,5 +1,6 @@ #define CLS #define MAIN "main.cc" +#define LIBRARY "modules" #define SOURCES "*.cc" #define OBJ_EXT ".o" #define SHAREDREQ "" @@ -9,7 +10,7 @@ #define CXXFLAGS " --std=c++17 -Wall -O2" \ " -fdiagnostics-color=never " #define IH ".ih" -//#define PRECOMP "-x c++-header" +#define PRECOMP "-x c++-header" #define REFRESH #define LDFLAGS "" #define ADD_LIBRARIES "" diff --git a/annotations/yo/advancedtemplates/examples/errcode/main.cc b/annotations/yo/advancedtemplates/examples/errcode/main.cc index dc60f12d..64664483 100644 --- a/annotations/yo/advancedtemplates/examples/errcode/main.cc +++ b/annotations/yo/advancedtemplates/examples/errcode/main.cc @@ -1,19 +1,55 @@ #include "main.ih" +//demo int main() try { + ErrorCondition &errorCond = ErrorCondition::instance(); + + std::cerr << CalculatorCategory::instance().name() << '\n' << + SimulatorCategory::instance().name() << '\n'; + + errorCond.addCondition("InputCond", "error in user request"); + errorCond.addCondition("UnavailCond", "function not available"); + errorCond.addCondition("SystemCond", "system failure"); + + // ec is an actual error code, belonging to some error enum + // the assert checks whether the specified error code belongs to + // the specified error condition + +// // also OK: ErrorCondition::Enum{}; +// std::error_condition cond = errorCond("InputCond"); + std::error_code ec = CalculatorError::TypeError; - assert(ec == ErrorSource::CalcError); - assert(ec != ErrorSource::SimError); - assert(ec != ErrorSource::InputError); + + std::cerr << "Enum value of UnavailCond = " << + errorCond("UnavailCond") << '\n'; + assert(ec != ErrorCondition::Enum{}); + assert(ec == errorCond("UnavailCond")); + assert(ec != errorCond("SystemCond")); + + ec = CalculatorError::MissingParentheses; + assert(ec == errorCond("InputCond")); ec = CalculatorError::ArityError; std::cout << ec << ' ' << ec.message() << '\n'; - throw std::system_error{ ec, "For demonstration purposes: " }; + throw std::system_error{ ec, "For demonstration purposes" }; } -catch (std::system_error &se) +catch (std::system_error const &se) { - std::cout << se.what() << ": " << se.code() << '\n'; + std::cout << "System Error: " << se.what() << ":\n" + " " << se.code() << '\n'; + //throw; cannot be rethrown!! } +/* + Produced output: + calculator + simulator + Enum value of UnavailCond = 2 + calculator:4 incorrect number of arguments + System Error: For demonstration purposes: incorrect number of arguments: + calculator:4 +*/ + +//= diff --git a/annotations/yo/advancedtemplates/examples/errcode/main.ih b/annotations/yo/advancedtemplates/examples/errcode/main.ih index 08482c67..c5e88ff7 100644 --- a/annotations/yo/advancedtemplates/examples/errcode/main.ih +++ b/annotations/yo/advancedtemplates/examples/errcode/main.ih @@ -1,11 +1,15 @@ #include + #include -// #include -// // #include -// #include - +#include + +#include + #include "calculatorerror/calculatorerror.h" +#include "calculatorcategory/calculatorcategory.h" + #include "simulatorerror/simulatorerror.h" +#include "simulatorcategory/simulatorcategory.h" -#include "errorsource/errorsource.h" +#include "errorcondition/errorcondition.h" diff --git a/annotations/yo/advancedtemplates/examples/errcode2/part/main.cc b/annotations/yo/advancedtemplates/examples/errcode/part/main.cc similarity index 61% rename from annotations/yo/advancedtemplates/examples/errcode2/part/main.cc rename to annotations/yo/advancedtemplates/examples/errcode/part/main.cc index 6151d1b3..cd98fd5b 100644 --- a/annotations/yo/advancedtemplates/examples/errcode2/part/main.cc +++ b/annotations/yo/advancedtemplates/examples/errcode/part/main.cc @@ -9,15 +9,17 @@ try { std::error_code ec = CalculatorError::ArityError; std::cout << ec << ' ' << ec.message() << '\n'; - throw std::system_error{ ec, "For demonstration purposes: " }; + throw std::system_error{ ec, "For demonstration purposes" }; } catch (std::system_error &se) { - std::cout << se.what() << ": " << se.code() << '\n'; + std::cout << se.what() << ":\n" + " " << se.code() << '\n'; } /* Outputs: calculator:4 incorrect number of arguments - For demonstration purposes: : incorrect number of arguments: calculator:4 + For demonstration purposes: incorrect number of arguments: + calculator:4 */ diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/data.cc b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/data.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/data.cc rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/data.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/frame b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/frame similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/frame rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/frame diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/instance.cc b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/instance.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/instance.cc rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/instance.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/makeerrorcode.cc b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/makeerrorcode.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/makeerrorcode.cc rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/makeerrorcode.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/message.cc b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/message.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/message.cc rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/message.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/name.cc b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/name.cc similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/name.cc rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/name.cc diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/simulatorcategory.h b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/simulatorcategory.h similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/simulatorcategory.h rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/simulatorcategory.h diff --git a/annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/simulatorcategory.ih b/annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/simulatorcategory.ih similarity index 100% rename from annotations/yo/advancedtemplates/examples/errcode2/simulatorcategory/simulatorcategory.ih rename to annotations/yo/advancedtemplates/examples/errcode/simulatorcategory/simulatorcategory.ih diff --git a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/simulatorerror.h b/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/simulatorerror.h index f9b6c288..50f6c7eb 100644 --- a/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/simulatorerror.h +++ b/annotations/yo/advancedtemplates/examples/errcode/simulatorerror/simulatorerror.h @@ -3,7 +3,7 @@ #include -//=simerrc +//enum enum class SimulatorError { // no 0 @@ -16,12 +16,6 @@ enum class SimulatorError }; //= -class SimulatorCategory: public std::error_category -{ - char const *name() const noexcept override; - std::string message(int ce) const override; -}; - namespace std { template <> @@ -29,10 +23,6 @@ namespace std {}; } -std::error_code make_error_code(SimulatorError ce); - -extern SimulatorCategory const simulatorCategory; - #endif diff --git a/annotations/yo/advancedtemplates/examples/errcode2/CLASSES b/annotations/yo/advancedtemplates/examples/errcode2/CLASSES deleted file mode 100644 index 9bf48a81..00000000 --- a/annotations/yo/advancedtemplates/examples/errcode2/CLASSES +++ /dev/null @@ -1,8 +0,0 @@ - // specific error categories, defined for this program -calculatorcategory -simulatorcategory - - // classes handling all error conditions -conditioncategory -errorcondition - diff --git a/annotations/yo/advancedtemplates/examples/errcode2/main.cc b/annotations/yo/advancedtemplates/examples/errcode2/main.cc deleted file mode 100644 index b84983bc..00000000 --- a/annotations/yo/advancedtemplates/examples/errcode2/main.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include "main.ih" - -int main() -try -{ - ErrorCondition &errorCond = ErrorCondition::instance(); - - std::cerr << CalculatorCategory::instance().name() << '\n' << - SimulatorCategory::instance().name() << '\n'; - - errorCond.addCondition("InputCond", "error in user request"); - errorCond.addCondition("UnavailCond", "function not available"); - errorCond.addCondition("SystemCond", "system failure"); - - // ec is an actual error code, belonging to some error enum - // the assert checks whether the specified error code belongs to - // the specified error condition - -// // also OK: ErrorCondition::Enum{}; -// std::error_condition cond = errorCond("InputCond"); - - std::error_code ec = CalculatorError::TypeError; - - std::cerr << "Enum value of UnavailCond = " << errorCond("UnavailCond") << - '\n'; - assert(ec != ErrorCondition::Enum{}); - assert(ec == errorCond("UnavailCond")); - assert(ec != errorCond("SystemCond")); - - ec = CalculatorError::MissingParentheses; - assert(ec == errorCond("InputCond")); - - ec = CalculatorError::ArityError; - std::cout << ec << ' ' << ec.message() << '\n'; - throw std::system_error{ ec, "For demonstration purposes: " }; -} -catch (std::system_error const &se) -{ - std::cout << "System Error: " << se.what() << ": " << se.code() << '\n'; - - //throw; cannot be rethrown!! - -} -catch (std::exception const &exc) -{ - std::cout << "Exception: " << exc.what() << '\n'; -} diff --git a/annotations/yo/advancedtemplates/examples/errcode2/main.ih b/annotations/yo/advancedtemplates/examples/errcode2/main.ih deleted file mode 100644 index c5e88ff7..00000000 --- a/annotations/yo/advancedtemplates/examples/errcode2/main.ih +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include -#include - -#include - -#include "calculatorerror/calculatorerror.h" -#include "calculatorcategory/calculatorcategory.h" - -#include "simulatorerror/simulatorerror.h" -#include "simulatorcategory/simulatorcategory.h" - -#include "errorcondition/errorcondition.h" -