diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2014-11-09 22:41:27 +0300 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2014-11-09 22:41:43 +0300 |
commit | 8b6a8e63079978646cd98a96d6ad178b28f3067c (patch) | |
tree | 5a75ffd52f3db1b1c6ec49ff9e8f59ecd159d222 /xs/src/libslic3r/PlaceholderParser.cpp | |
parent | 6135a9fb8bb4582fb6918400d874a5689b3bc4c4 (diff) |
Ported PlaceholderParser::update_timestamp() to XS
Note that Slic3r version number is now located in libslic3r.h
Diffstat (limited to 'xs/src/libslic3r/PlaceholderParser.cpp')
-rw-r--r-- | xs/src/libslic3r/PlaceholderParser.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/xs/src/libslic3r/PlaceholderParser.cpp b/xs/src/libslic3r/PlaceholderParser.cpp index c384afa32..31056dd2c 100644 --- a/xs/src/libslic3r/PlaceholderParser.cpp +++ b/xs/src/libslic3r/PlaceholderParser.cpp @@ -1,18 +1,50 @@ #include "PlaceholderParser.hpp" - +#include <ctime> +#include <iomanip> +#include <sstream> namespace Slic3r { - PlaceholderParser::PlaceholderParser() { + this->_single["version"] = SLIC3R_VERSION; // TODO: port these methods to C++, then call them here // this->apply_env_variables(); - // this->update_timestamp(); + this->update_timestamp(); +} + +void +PlaceholderParser::update_timestamp() +{ + time_t rawtime; + time(&rawtime); + struct tm* timeinfo = localtime(&rawtime); + + { + std::ostringstream ss; + ss << (1900 + timeinfo->tm_year); + ss << std::setw(2) << std::setfill('0') << (1 + timeinfo->tm_mon); + ss << std::setw(2) << std::setfill('0') << timeinfo->tm_mday; + ss << "-"; + ss << std::setw(2) << std::setfill('0') << timeinfo->tm_hour; + ss << std::setw(2) << std::setfill('0') << timeinfo->tm_min; + ss << std::setw(2) << std::setfill('0') << timeinfo->tm_sec; + this->_single["timestamp"] = ss.str(); + } + this->_single["year"] = this->_int_to_string(1900 + timeinfo->tm_year); + this->_single["month"] = this->_int_to_string(1 + timeinfo->tm_mon); + this->_single["day"] = this->_int_to_string(timeinfo->tm_mday); + this->_single["hour"] = this->_int_to_string(timeinfo->tm_hour); + this->_single["minute"] = this->_int_to_string(timeinfo->tm_min); + this->_single["second"] = this->_int_to_string(timeinfo->tm_sec); } -PlaceholderParser::~PlaceholderParser() +std::string +PlaceholderParser::_int_to_string(int value) const { + std::ostringstream ss; + ss << value; + return ss.str(); } void PlaceholderParser::apply_config(DynamicPrintConfig &config) @@ -85,6 +117,12 @@ void PlaceholderParser::apply_config(DynamicPrintConfig &config) } } +void +PlaceholderParser::set(const std::string &key, const std::string &value) +{ + this->_single[key] = value; +} + std::ostream& operator<<(std::ostream &stm, const Pointf &pointf) { return stm << pointf.x << "," << pointf.y; |