Skip to content

Commit

Permalink
Finish Release-2
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/doubleOperators.hpp
#	include/genericTrace.hpp
#	include/variableTracer.hpp
#	tests/CMakeLists.txt
#	tests/main.cpp
  • Loading branch information
Galfurian committed Aug 20, 2018
2 parents 3715d5f + 139b922 commit bf4a4a9
Show file tree
Hide file tree
Showing 10 changed files with 370 additions and 213 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ matrix:
script:
- mkdir build
- cd build
- cmake -DCMAKE_CXX_COMPILER=$COMPILER .. && make
- cmake -DCMAKE_CXX_COMPILER=$COMPILER ..
- make
- make test
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# CPPTracer [![Build Status](https://travis-ci.org/Galfurian/CPPTracer.svg?branch=master)](https://travis-ci.org/Galfurian/CPPTracer)

The VariableTracer is a class which allows to generate vcd files from c++ variables.
It may be of use for tracing variables during the simulation of both discrete and continuous time models. The tracer itself is pretty simple to use.

Look at main.cpp for an example of usage.
The VariableTracer is a class which allows to generate vcd files from
c++ variables. It can be of use for tracing variables during the simulation of
both discrete and continuous time models. The tracer itself is pretty simple
to use. Have a look at the test code (inside tests) for an example of use.

## Structure
- src : Application sources.
- lib : Support libraries for the application.
- doc : Documentation including auto-generated doxygen.
- include : Application headers.
- tests : Sources for testing.
- doc : Documentation including auto-generated doxygen.
- tests : Sources for testing.
17 changes: 8 additions & 9 deletions include/doubleOperators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,21 @@
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define Max(a, b) ((a) > (b) ? (a) : (b))

inline bool is_equal(double a, double b, double tolerance = 1e-09)
template<typename T>
inline bool is_equal(T a, T b, double tolerance = 1e-09)
{
#if 1
return (static_cast<int>(Max(Abs(a), Abs(b)) / tolerance))
? (Abs(a - b) < tolerance) : true;
#else
return Abs(a - b) < tolerance;
#endif
T d = Max(Abs(a), Abs(b));
return static_cast<int>(d * 1e09) == 0 || (Abs(a - b) / d) <= tolerance;
}

inline bool is_lequal(double a, double b, double tolerance = 1e-09)
template<typename T>
inline bool is_lequal(T a, T b, double tolerance = 1e-09)
{
return is_equal(a, b, tolerance) || (a < b);
}

inline bool is_gequal(double a, double b, double tolerance = 1e-09)
template<typename T>
inline bool is_gequal(T a, T b, double tolerance = 1e-09)
{
return is_equal(a, b, tolerance) || (a > b);
}
119 changes: 100 additions & 19 deletions include/genericTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,63 @@ inline std::string GenericTraceWrapper<bool>::getVar()
}

template<>
inline std::string GenericTraceWrapper<int>::getVar()
inline std::string GenericTraceWrapper<int8_t>::getVar()
{
ss.str("");
ss << "$var integer 32 " << getSymbol() << " " << getName() << " $end\n";
ss << "$var integer 8 " << getSymbol() << " " << getName() << " $end\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<short>::getVar()
inline std::string GenericTraceWrapper<int16_t>::getVar()
{
ss.str("");
ss << "$var integer 16 " << getSymbol() << " " << getName() << " $end\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<int32_t>::getVar()
{
ss.str("");
ss << "$var integer 32 " << getSymbol() << " " << getName() << " $end\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<int64_t>::getVar()
{
ss.str("");
ss << "$var integer 64 " << getSymbol() << " " << getName() << " $end\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<uint8_t>::getVar()
{
ss.str("");
ss << "$var integer 32 " << getSymbol() << " " << getName() << " $end\n";
ss << "$var integer 8 " << getSymbol() << " " << getName() << " $end\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<uint16_t>::getVar()
{
ss.str("");
ss << "$var integer 16 " << getSymbol() << " " << getName() << " $end\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<uint32_t>::getVar()
{
ss.str("");
ss << "$var integer 32 " << getSymbol() << " " << getName() << " $end\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<unsigned int>::getVar()
inline std::string GenericTraceWrapper<uint64_t>::getVar()
{
ss.str("");
ss << "$var integer 64 " << getSymbol() << " " << getName() << " $end\n";
Expand All @@ -183,6 +207,12 @@ inline std::string GenericTraceWrapper<double>::getVar()
return "$var real 1 " + getSymbol() + " " + getName() + " $end\n";
}

template<>
inline std::string GenericTraceWrapper<long double>::getVar()
{
return "$var real 1 " + getSymbol() + " " + getName() + " $end\n";
}

template<>
inline std::string GenericTraceWrapper<std::vector<bool>>::getVar()
{
Expand All @@ -201,13 +231,25 @@ inline bool GenericTraceWrapper<bool>::hasChanged()
}

template<>
inline bool GenericTraceWrapper<int>::hasChanged()
inline bool GenericTraceWrapper<int8_t>::hasChanged()
{
return (previous != (*ptr));
}

template<>
inline bool GenericTraceWrapper<int16_t>::hasChanged()
{
return (previous != (*ptr));
}

template<>
inline bool GenericTraceWrapper<int32_t>::hasChanged()
{
return (previous != (*ptr));
}

template<>
inline bool GenericTraceWrapper<short>::hasChanged()
inline bool GenericTraceWrapper<int64_t>::hasChanged()
{
return (previous != (*ptr));
}
Expand All @@ -225,7 +267,13 @@ inline bool GenericTraceWrapper<uint16_t>::hasChanged()
}

template<>
inline bool GenericTraceWrapper<unsigned int>::hasChanged()
inline bool GenericTraceWrapper<uint32_t>::hasChanged()
{
return (previous != (*ptr));
}

template<>
inline bool GenericTraceWrapper<uint64_t>::hasChanged()
{
return (previous != (*ptr));
}
Expand All @@ -238,25 +286,28 @@ inline bool GenericTraceWrapper<float>::hasChanged()

template<>
inline bool GenericTraceWrapper<double>::hasChanged()
{
return !is_equal(previous, (*ptr), 1e-12);
}

template<>
inline bool GenericTraceWrapper<long double>::hasChanged()
{
return !is_equal(previous, (*ptr), 1e-24);
}

template<>
inline bool GenericTraceWrapper<std::vector<bool>>::hasChanged()
{
auto it_prev = previous.begin();
auto it_curr = ptr->begin();
auto it_prev = previous.begin(), it_curr = ptr->begin();
while ((it_prev != previous.end()) && (it_curr != ptr->end()))
{
if ((*it_curr) != (*it_prev)) return true;
++it_prev;
++it_curr;
++it_prev, ++it_curr;
}
return false;
}


// ----------------------------------------------------------------------------
// Provides specific values.
template<>
Expand All @@ -266,31 +317,53 @@ inline std::string GenericTraceWrapper<bool>::getValue()
}

template<>
inline std::string GenericTraceWrapper<int>::getValue()
inline std::string GenericTraceWrapper<int8_t>::getValue()
{
return "b" + std::bitset<32>(*ptr).to_string() + " " + getSymbol() + "\n";
return "b" + std::bitset<8>(
static_cast<uint8_t>(*ptr)).to_string() + " " + getSymbol() + "\n";
}

template<>
inline std::string GenericTraceWrapper<short>::getValue()
inline std::string GenericTraceWrapper<int16_t>::getValue()
{
return "b" + std::bitset<32>(*ptr).to_string() + " " + getSymbol() + "\n";
return "b" + std::bitset<16>(
static_cast<uint16_t>(*ptr)).to_string() + " " + getSymbol() + "\n";
}

template<>
inline std::string GenericTraceWrapper<int32_t>::getValue()
{
return "b" + std::bitset<32>(
static_cast<uint32_t>(*ptr)).to_string() + " " + getSymbol() + "\n";
}

template<>
inline std::string GenericTraceWrapper<int64_t>::getValue()
{
return "b" + std::bitset<64>(
static_cast<uint64_t>(*ptr)).to_string() + " " + getSymbol() + "\n";
}

template<>
inline std::string GenericTraceWrapper<uint8_t>::getValue()
{
return "b" + std::bitset<32>(*ptr).to_string() + " " + getSymbol() + "\n";
return "b" + std::bitset<8>(*ptr).to_string() + " " + getSymbol() + "\n";
}

template<>
inline std::string GenericTraceWrapper<uint16_t>::getValue()
{
return "b" + std::bitset<16>(*ptr).to_string() + " " + getSymbol() + "\n";
}

template<>
inline std::string GenericTraceWrapper<uint32_t>::getValue()
{
return "b" + std::bitset<32>(*ptr).to_string() + " " + getSymbol() + "\n";
}

template<>
inline std::string GenericTraceWrapper<unsigned int>::getValue()
inline std::string GenericTraceWrapper<uint64_t>::getValue()
{
return "b" + std::bitset<64>(*ptr).to_string() + " " + getSymbol() + "\n";
}
Expand All @@ -311,6 +384,14 @@ inline std::string GenericTraceWrapper<double>::getValue()
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<long double>::getValue()
{
ss.str("");
ss << "r" << (*ptr) << " " << getSymbol() << "\n";
return ss.str();
}

template<>
inline std::string GenericTraceWrapper<std::vector<bool>>::getValue()
{
Expand Down
82 changes: 0 additions & 82 deletions include/traceNameGenerator.hpp

This file was deleted.

Loading

0 comments on commit bf4a4a9

Please sign in to comment.