#pragma once
#include <memory>
#include <iostream>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <tuple>
#include <map>
#include <vector>
#include <cmath>
......@@ -25,19 +25,22 @@ public:
double latitude;
double longitude;
double altitude;
public:
coordinates();
coordinates(const double p_latitude, const double p_longitude, const double p_altitude);
virtual ~coordinates() { };
virtual ~coordinates(){};
inline const coordinates to_radian() const { return coordinates(latitude * PI / 180, longitude * PI / 180, altitude); };
const bool is_valid_coordinates() const;;
const double distance_less_than_1km(const coordinates& p) const; // this position has origin
const double distance(const coordinates& p) const; // this position has origin
const bool is_valid_coordinates() const;
;
const double distance_less_than_1km(const coordinates &p) const; // this position has origin
const double distance(const coordinates &p) const; // this position has origin
};
class point {
public:
double x, y, z;
public:
point();
point(const double p_x, const double p_y, const double p_z);
......@@ -51,11 +54,12 @@ class geospacial {
const std::string process_properties(const Json::Value p_properties);
const std::vector<polygon> process_geometry(const Json::Value p_geometry);
const std::vector<polygon> extract_polygons(const Json::Value p_polygon);
const double CalcAngleSum_2d(const point& p1, const point& p2) const;
const int is_inside_polygon(const polygon& p_polygon, const point& q) const;
const double CalcAngleSum_2d(const point &p1, const point &p2) const;
const int is_inside_polygon(const polygon &p_polygon, const point &q) const;
public:
geospacial() { };
virtual ~geospacial() { };
int load_countries_map(const std::string& p_file);
const int is_in_country(const std::string& p_country, const coordinates& p_position);
geospacial(){};
virtual ~geospacial(){};
int load_countries_map(const std::string &p_file);
const int is_in_country(const std::string &p_country, const coordinates &p_position);
};
#include "loggers.hh"
std::unique_ptr<loggers> loggers::_instance = static_cast<std::unique_ptr<loggers>>(new loggers);
......@@ -10,11 +10,11 @@
*/
#pragma once
#include <memory>
#include <cstdarg>
#include <ctime>
#include <map>
#include <memory>
#include <string>
#include <ctime>
#include <cstdarg>
/**
class Base_Type;
......@@ -42,14 +42,15 @@ using namespace std; // Required for isnan()
class loggers {
private: //! \privatesection
static std::unique_ptr<loggers> _instance; //! Smart pointer to the unique instance of the logger framework
std::map<std::string, std::clock_t> _times; //! Timer used to measure execution time between calls to methods \loggers::set_start_time and \loggers::set_stop_time
std::map<std::string, std::clock_t>
_times; //! Timer used to measure execution time between calls to methods \loggers::set_start_time and \loggers::set_stop_time
/*!
* \brief Default constructor
* Create a new instance of the loggers class
* \private
*/
explicit loggers() : _times() { };
explicit loggers() : _times(){};
inline void log_time_exec(const char *p_fmt, ...);
......@@ -57,14 +58,14 @@ public: //! \publicsection
/*!
* \brief Default destructor
*/
virtual ~loggers() {};
virtual ~loggers(){};
/*!
* \fn static loggers& get_instance();
* \brief Accessor for the unique instance of the logger framework
* \inline
*/
static inline loggers& get_instance() { return *_instance.get(); };
static inline loggers &get_instance() { return *_instance.get(); };
/*!
* \fn void log_to_hexa(const char *p_prompt, const TTCN_Buffer& buffer);
......@@ -73,7 +74,7 @@ public: //! \publicsection
* \param[in] buffer The TTCN_Buffer buffer to dump
* \inline
*/
inline void log_to_hexa(const char *p_prompt, const TTCN_Buffer& buffer);
inline void log_to_hexa(const char *p_prompt, const TTCN_Buffer &buffer);
/*!
* \fn void log_to_hexa(const char *p_prompt, const OCTETSTRING& msg);
* \brief Hexa dump of the \see OCTETSTRING buffer
......@@ -81,7 +82,7 @@ public: //! \publicsection
* \param[in] msg The OCTETSTRING buffer to dump
* \inline
*/
inline void log_to_hexa(const char *p_prompt, const OCTETSTRING& msg);
inline void log_to_hexa(const char *p_prompt, const OCTETSTRING &msg);
/*!
* \fn void log_to_hexa(const char *p_prompt, const unsigned char* msg, const size_t msg_size);
* \brief Hexa dump of the provided buffer
......@@ -89,7 +90,7 @@ public: //! \publicsection
* \param[in] msg The buffer to dump
* \inline
*/
inline void log_to_hexa(const char *p_prompt, const unsigned char* msg, const size_t msg_size);
inline void log_to_hexa(const char *p_prompt, const unsigned char *msg, const size_t msg_size);
/*!
* \fn void log_msg(const char *p_prompt, const Base_Type& p_type);
* \brief Debug log of TITAN data structures
......@@ -97,7 +98,7 @@ public: //! \publicsection
* \param[in] msg The TITAN data structure to log
* \inline
*/
inline void log_msg(const char *p_prompt, const Base_Type& p_type);
inline void log_msg(const char *p_prompt, const Base_Type &p_type);
/*!
* \fn void log(const char *p_fmt, ...);
* \brief Debug message based on printf-compliant formatting message
......@@ -114,7 +115,7 @@ public: //! \publicsection
* \param[in] msg The TITAN data structure to log
* \inline
*/
inline void user_msg(const char *p_prompt, const Base_Type& p_type);
inline void user_msg(const char *p_prompt, const Base_Type &p_type);
/*!
* \fn void user(const char *p_fmt, ...);
* \brief User message based on printf-compliant formatting message
......@@ -131,7 +132,7 @@ public: //! \publicsection
* \param[in] msg The TITAN data structure to log
* \inline
*/
inline void warning_msg(const char *p_prompt, const Base_Type& p_type);
inline void warning_msg(const char *p_prompt, const Base_Type &p_type);
/*!
* \fn void user(const char *p_fmt, ...);
* \brief Warning message based on printf-compliant formatting message
......@@ -156,7 +157,7 @@ public: //! \publicsection
* \param[in] p_time_key A timer identifier (any string)
* \inline
*/
inline void set_start_time(std::string& p_time_key);
inline void set_start_time(std::string &p_time_key);
/*!
* \fn void set_stop_time(std::string& p_time_key, float& p_time);
* \brief Stop execution time measurement
......@@ -164,51 +165,46 @@ public: //! \publicsection
* \param[out] p_time The execution time measured in milliseconds
* \inline
*/
inline void set_stop_time(std::string& p_time_key, float& p_time);
inline void set_stop_time(std::string &p_time_key, float &p_time);
}; // End of class loggers
void loggers::log_to_hexa(const char *p_prompt, const TTCN_Buffer & buffer)
{
void loggers::log_to_hexa(const char *p_prompt, const TTCN_Buffer &buffer) {
TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED);
TTCN_Logger::log_event_str(p_prompt);
buffer.log();
TTCN_Logger::end_event();
}
void loggers::log_to_hexa(const char *p_prompt, const OCTETSTRING& msg)
{
void loggers::log_to_hexa(const char *p_prompt, const OCTETSTRING &msg) {
TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED);
TTCN_Logger::log_event_str(p_prompt);
TTCN_Logger::log_event("Size: %d,\nMsg: ", msg.lengthof());
for(int i = 0; i < msg.lengthof(); i++) {
TTCN_Logger::log_event(" %02x", ((const unsigned char*)msg)[i]);
for (int i = 0; i < msg.lengthof(); i++) {
TTCN_Logger::log_event(" %02x", ((const unsigned char *)msg)[i]);
}
TTCN_Logger::log_event("\n");
TTCN_Logger::end_event();
}
void loggers::log_to_hexa(const char *p_prompt, const unsigned char* msg, const size_t msg_size)
{
void loggers::log_to_hexa(const char *p_prompt, const unsigned char *msg, const size_t msg_size) {
TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED);
TTCN_Logger::log_event_str(p_prompt);
for(size_t i = 0; i < msg_size; i++) {
for (size_t i = 0; i < msg_size; i++) {
TTCN_Logger::log_event(" %02x", *(msg + i));
}
TTCN_Logger::log_event("\n");
TTCN_Logger::end_event();
}
void loggers::log_msg(const char *p_prompt, const Base_Type& p_type)
{
void loggers::log_msg(const char *p_prompt, const Base_Type &p_type) {
TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED);
TTCN_Logger::log_event_str(p_prompt);
p_type.log();
TTCN_Logger::end_event();
}
void loggers::log(const char *p_fmt, ...)
{
void loggers::log(const char *p_fmt, ...) {
TTCN_Logger::begin_event(TTCN_Logger::DEBUG_UNQUALIFIED);
va_list args;
va_start(args, p_fmt);
......@@ -217,16 +213,14 @@ void loggers::log(const char *p_fmt, ...)
TTCN_Logger::end_event();
}
void loggers::user_msg(const char *p_prompt, const Base_Type& p_type)
{
void loggers::user_msg(const char *p_prompt, const Base_Type &p_type) {
TTCN_Logger::begin_event(TTCN_Logger::USER_UNQUALIFIED);
TTCN_Logger::log_event_str(p_prompt);
p_type.log();
TTCN_Logger::end_event();
}
void loggers::user(const char *p_fmt, ...)
{
void loggers::user(const char *p_fmt, ...) {
TTCN_Logger::begin_event(TTCN_Logger::USER_UNQUALIFIED);
va_list args;
va_start(args, p_fmt);
......@@ -235,8 +229,7 @@ void loggers::user(const char *p_fmt, ...)
TTCN_Logger::end_event();
}
void loggers::warning(const char *p_fmt, ...)
{
void loggers::warning(const char *p_fmt, ...) {
TTCN_Logger::begin_event(TTCN_Logger::WARNING_UNQUALIFIED);
va_list args;
va_start(args, p_fmt);
......@@ -245,40 +238,32 @@ void loggers::warning(const char *p_fmt, ...)
TTCN_Logger::end_event();
}
void loggers::warning_msg(const char *p_prompt, const Base_Type& p_type)
{
void loggers::warning_msg(const char *p_prompt, const Base_Type &p_type) {
TTCN_Logger::begin_event(TTCN_Logger::WARNING_UNQUALIFIED);
TTCN_Logger::log_event_str(p_prompt);
p_type.log();
TTCN_Logger::end_event();
}
void loggers::error(const char *p_fmt, ...)
{
void loggers::error(const char *p_fmt, ...) {
va_list args;
va_start(args, p_fmt);
TTCN_error(p_fmt, args);
va_end(args);
}
void loggers::set_start_time(std::string& p_time_key)
{
_times[p_time_key] = std::clock();
}
void loggers::set_start_time(std::string &p_time_key) { _times[p_time_key] = std::clock(); }
void loggers::set_stop_time(std::string& p_time_key, float& p_time)
{
void loggers::set_stop_time(std::string &p_time_key, float &p_time) {
std::map<std::string, std::clock_t>::iterator it = _times.find(p_time_key);
if (it != loggers::_times.end()) {
p_time = (std::clock() - _times[p_time_key]) * 1000.0 / CLOCKS_PER_SEC; // in milliseconds
_times.erase(it);
loggers::get_instance().log_time_exec("%s: Execution duration: %f ms", p_time_key.c_str(), p_time);
}
}
void loggers::log_time_exec(const char *p_fmt, ...)
{
void loggers::log_time_exec(const char *p_fmt, ...) {
TTCN_Logger::begin_event(TTCN_Logger::EXECUTOR_RUNTIME);
va_list args;
va_start(args, p_fmt);
......@@ -286,4 +271,3 @@ void loggers::log_time_exec(const char *p_fmt, ...)
va_end(args);
TTCN_Logger::end_event();
}
#!/bin/bash
# Debug mode
set -vx
#set -e
find ../ccsrc -type f -name "*.hh" -exec clang-format -style=file -i {} \;
find ../ccsrc -type f -name "*.cc" -exec clang-format -style=file -i {} \;
find ../ccsrc -type f -name "*.h" -exec clang-format -style=file -i {} \;
find ../ccsrc -type f -name "*.c" -exec clang-format -style=file -i {} \;