Browse files

Calculate time with boost::chrono (broke binary compatibility)

  • Loading branch information...
1 parent 18aa759 commit 2157e3e164a56d49bffded9506d08ad84a5734ae @massix committed May 17, 2012
Showing with 19 additions and 3 deletions.
  1. +4 −0 include/PM_IP_Parser.h
  2. +3 −3 src/CMakeLists.txt
  3. +12 −0 src/PM_IP_Parser.cpp
View
4 include/PM_IP_Parser.h
@@ -28,6 +28,8 @@
#include <string>
#include <vector>
#include <stdexcept>
+#include <boost/chrono.hpp>
+
#include "PM_IP_IniElement.h"
typedef std::vector<PhantomMenace::IniParser::IniElement> Elements_t;
@@ -51,13 +53,15 @@ class Parser {
const throw(std::runtime_error);
bool hasElement(const std::string& iElementName) const;
+ double getParsingDuration() const;
private:
Parser();
Parser(const Parser& right);
Parser& operator=(const Parser& right);
Elements_t elements;
+ boost::chrono::duration<double> parsing_duration;
};
} /* namespace IniParser */
View
6 src/CMakeLists.txt
@@ -6,8 +6,8 @@ file(GLOB SOURCES *.cpp)
file(GLOB HEADERS ${libPmIniParser_SOURCE_DIR}/include/*.h)
set(MajorVersion 1)
-set(BinaryVersion 4)
-set(MinorVersion 4)
+set(BinaryVersion 5)
+set(MinorVersion 0)
set(FullVersion ${MajorVersion}.${BinaryVersion}.${MinorVersion})
add_definitions(
@@ -16,7 +16,7 @@ add_definitions(
-DBINARYVERSION=${BinaryVersion}
-DMINORVERSION=${MinorVersion})
-find_package(Boost COMPONENTS regex-mt)
+find_package(Boost COMPONENTS regex chrono system)
include_directories(${Boost_INCLUDE_DIRS} ${libPmIniParser_SOURCE_DIR}/include)
View
12 src/PM_IP_Parser.cpp
@@ -23,6 +23,7 @@
#include "PM_IP_Parser.h"
#include <boost/regex.hpp>
+#include <boost/chrono.hpp>
#include <cstdlib>
#include <stdexcept>
@@ -55,6 +56,7 @@ Parser* Parser::getInstancePtr()
void Parser::resetInstance()
{
getInstance().elements.clear();
+ getInstance().parsing_duration = boost::chrono::duration<double>();
}
void Parser::clearInstance()
@@ -66,6 +68,9 @@ void Parser::parse(const char *raw)
{
resetInstance();
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+
if (raw == 0)
return;
@@ -125,6 +130,8 @@ void Parser::parse(const char *raw)
rc = raw[++lastIndex];
}
+
+ parsing_duration = boost::chrono::system_clock::now() - start;
}
void Parser::parseFromFile(const std::string& iFileName)
@@ -176,5 +183,10 @@ bool Parser::hasElement(const std::string& iElementName) const
return false;
}
+double Parser::getParsingDuration() const
+{
+ return parsing_duration.count();
+}
+
} /* namespace IniParser */
} /* namespace PhantomMenace */

0 comments on commit 2157e3e

Please sign in to comment.