Commit 215130e3 authored by Tomáš Jakubec's avatar Tomáš Jakubec
Browse files

automatic traits algorithms.

To achieve the maximal efficiency of traits approach is necessary to
change name type from std::string to const char*.
Moreover, I had to make the default trait public in another way. There
is a function creating and returning the generated Trait. At first sight
is seemed to me as bad idea, but the compiler can not work so
efficiently with it. Thus, it is better to have static function which
generates the object of traits.
parent d2a1f3b3
Loading
Loading
Loading
Loading
+958 −175

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ HEADERS += \
    ../src/NumericStaticArray/InlineArrayOperations.h \
    ../src/Traits/CustomTypeTraits.h \
    ../src/Traits/MemberApproach/MemberApproach.h \
    ../src/Traits/TraitsAlgorithm/TraitsAlgorithm.h \
    ../src/UnstructuredMesh/MeshDataContainer/MeshDataContainer.h \
    ../src/UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataReader.h \
    ../src/UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataWriter.h \
+16 −0
Original line number Diff line number Diff line
@@ -25,9 +25,25 @@ public:
    template<typename MSGTYPE>
    static void writeMessage(const char* prefix, int line, const char* sourceFile, const MSGTYPE& message) {

#ifdef CONSOLE_COLORED_OUTPUT
#ifdef _WIN32
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        std::cerr << prefix << " " << sourceFile << " << " << line << " >> ==> ";
        SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
        VariableExport<>::exportVariable(std::cerr, message);
        SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
        std::cerr << " <==\n";
#else
        std::cerr << prefix << " " << sourceFile << " << " << line << " >> ==> \033[0;32m";
        VariableExport<>::exportVariable(std::cerr, message);
        std::cerr << "\033[0m <==\n";

#endif
#else
        std::cerr << prefix << " " << sourceFile << " << " << line << " >> ==> ";
        VariableExport<>::exportVariable(std::cerr, message);
        std::cerr << " <==\n";
#endif
    }

    template<typename VAR_NAME, typename VAR, typename ... REST>
+0 −4
Original line number Diff line number Diff line
#ifndef DEBUG_H
#define DEBUG_H





#ifndef UNDEBUG
#include "../Macros/MacroForEach.h"
#include <iostream>
+9 −9
Original line number Diff line number Diff line
@@ -181,9 +181,9 @@ struct VariableExport {
    };

    template<typename T, unsigned int Index>
    struct PrintClass<T, Index, typename std::enable_if<Index == Traits<T>::ttype::size() - 1>::type>{
    struct PrintClass<T, Index, typename std::enable_if<Index == Traits<T>::traitsType::size() - 1>::type>{
        static void print(std::ostream& ost, const T &traitedClass){
            ost << '"' << Traits<T>::tr.template getName<Traits<T>::ttype::size() - 1>() << "\" : ";
            ost << '"' << Traits<T>::tr.template getName<Traits<T>::traitsType::size() - 1>() << "\" : ";
            VariableExport::exportVariable(ost, Traits<T>::tr.template getValue<Traits<T>::tr.size() - 1>(traitedClass));
        }
    };
@@ -196,7 +196,7 @@ struct VariableExport {
         >::type
    {
        ost << "{ ";
        PrintClass<typename DefaultIOTraits<T>::ttype>::print(ost, traitedClass);
        PrintClass<typename DefaultIOTraits<T>::traitsType>::print(ost, traitedClass);
        ost << " }";
    }

@@ -359,8 +359,8 @@ struct VariableExport<VARIABLE_EXPORT_METHOD::stdio> {
    struct PrintClass{
        static std::string print(const T &traitedClass){
            std::string res;
            res += '"' + Traits<T>::ttype::template getName<Index>() + "\" : ";
            VariableExport::exportVariable(Traits<T>::ttype::template getReference<Index>()->getValue(traitedClass));
            res += '"' + Traits<T>::traitsType::template getName<Index>() + "\" : ";
            VariableExport::exportVariable(Traits<T>::traitsType::template getReference<Index>()->getValue(traitedClass));
            res += ", ";
            res += PrintClass<T, Index + 1>::print( traitedClass);
            return res;
@@ -390,11 +390,11 @@ struct VariableExport<VARIABLE_EXPORT_METHOD::stdio> {
    };

    template<typename T, unsigned int Index>
    struct PrintClass<T, Index, typename std::enable_if<Index == Traits<T>::ttype::size() - 1>::type>{
    struct PrintClass<T, Index, typename std::enable_if<Index == Traits<T>::traitsType::size() - 1>::type>{
        static std::string print(const T &traitedClass){
            std::string res;
            res += '"' + Traits<T>::ttype::template getName<Traits<T>::ttype::size() - 1>() + "\" : ";
            VariableExport::exportVariable(Traits<T>::ttype::template getReference<Traits<T>::ttype::size() - 1>()->getValue(traitedClass));
            res += '"' + Traits<T>::traitsType::template getName<Traits<T>::traitsType::size() - 1>() + "\" : ";
            VariableExport::exportVariable(Traits<T>::traitsType::template getReference<Traits<T>::traitsType::size() - 1>()->getValue(traitedClass));
            return res;
        }
    };
@@ -409,7 +409,7 @@ struct VariableExport<VARIABLE_EXPORT_METHOD::stdio> {
    {
        std::string res;
        res += "{ ";
        res += PrintClass<typename DefaultIOTraits<T>::ttype>::print(traitedClass);
        res += PrintClass<typename DefaultIOTraits<T>::traitsType>::print(traitedClass);
        res += " }";
        return res;
    }
Loading