1 //******************************************************************************
2 ///
3 /// @file base/image/metadata.cpp
4 ///
5 /// Implementations related to image metadata.
6 ///
7 /// @copyright
8 /// @parblock
9 ///
10 /// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11 /// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
12 ///
13 /// POV-Ray is free software: you can redistribute it and/or modify
14 /// it under the terms of the GNU Affero General Public License as
15 /// published by the Free Software Foundation, either version 3 of the
16 /// License, or (at your option) any later version.
17 ///
18 /// POV-Ray is distributed in the hope that it will be useful,
19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 /// GNU Affero General Public License for more details.
22 ///
23 /// You should have received a copy of the GNU Affero General Public License
24 /// along with this program.  If not, see <http://www.gnu.org/licenses/>.
25 ///
26 /// ----------------------------------------------------------------------------
27 ///
28 /// POV-Ray is based on the popular DKB raytracer version 2.12.
29 /// DKBTrace was originally written by David K. Buck.
30 /// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
31 ///
32 /// @endparblock
33 ///
34 //******************************************************************************
35 
36 // Unit header file must be the first file included within POV-Ray *.cpp files (pulls in config)
37 #include "base/image/metadata.h"
38 
39 #include <cstdio>
40 
41 // POV-Ray base header files
42 #include "base/version_info.h"
43 
44 // this must be the last file included
45 #include "base/povdebug.h"
46 
47 namespace pov_base
48 {
49 
Metadata()50 Metadata::Metadata()
51 {
52     mTimestamp = boost::posix_time::second_clock::universal_time();
53 }
54 
~Metadata()55 Metadata::~Metadata()
56 {}
57 
getSoftware() const58 string Metadata::getSoftware() const
59 {
60     return "POV-Ray v" POV_RAY_SOURCE_VERSION;
61 }
62 
getComment1() const63 string Metadata::getComment1() const
64 {
65 #ifdef METADATA_PLATFORM_STRING
66     // METADATA_PLATFORM_STRING should be in a form similar to 'i686-pc-linux-gnu', 'i386-pc-win', etc.
67     return string("Platform: ") + METADATA_PLATFORM_STRING;
68 #else
69     return string();
70 #endif
71 }
72 
getComment2() const73 string Metadata::getComment2() const
74 {
75 #ifdef METADATA_COMPILER_STRING
76     // METADATA_COMPILER_STRING should be in a form similar to 'g++ 4.4.3', 'msvc 10.0', etc.
77     return string("Compiler: ") + METADATA_COMPILER_STRING;
78 #else
79     return string();
80 #endif
81 }
82 
getComment3() const83 string Metadata::getComment3() const
84 {
85 #ifdef METADATA_COMMENT_3
86     // NB it is legal for METADATA_COMMENT_3 to be a function returning string
87     // Note that it may be called more than once
88     return string(METADATA_COMMENT_3);
89 #else
90     return string();
91 #endif
92 }
93 
getComment4() const94 string Metadata::getComment4() const
95 {
96 #ifdef METADATA_COMMENT_4
97     // NB it is legal for METADATA_COMMENT_4 to be a function returning string
98     // Note that it may be called more than once
99     return string(METADATA_COMMENT_4);
100 #else
101     return string();
102 #endif
103 }
104 
getDateTime() const105 string Metadata::getDateTime() const
106 {
107     // Not using boost's `to_iso_extended_string` because that would mean we couldn't reliably
108     // get away with using the boost date_time library in header-only mode.
109     char s[21]; // 10 (date) + 1 (blank) + 8 (time) + 1 (timezone "Z") + 1 (trailing NUL)
110     std::snprintf(s, sizeof(s), "%04d-%02d-%02d %02d:%02d:%02dZ", getYear(), getMonth(), getDay(), getHour(), getMin(), getSec());
111     return string(s);
112 }
113 
getYear() const114 int Metadata::getYear() const
115 {
116     return mTimestamp.date().year();
117 }
118 
getMonth() const119 int Metadata::getMonth() const
120 {
121     return mTimestamp.date().month();
122 }
123 
getDay() const124 int Metadata::getDay() const
125 {
126     return mTimestamp.date().day();
127 }
128 
getHour() const129 int Metadata::getHour() const
130 {
131     return mTimestamp.time_of_day().hours();
132 }
133 
getMin() const134 int Metadata::getMin() const
135 {
136     return mTimestamp.time_of_day().minutes();
137 }
138 
getSec() const139 int Metadata::getSec() const
140 {
141     return mTimestamp.time_of_day().seconds();
142 }
143 
144 }
145