00001 #ifndef VERSION_RECORD_IMPLEMENTATION_FILE
00002 #define VERSION_RECORD_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "function.h"
00019 #include "string_array.h"
00020 #include "version_record.h"
00021
00022 #include <ctype.h>
00023
00024 version::version()
00025 : _components(new string_array)
00026 {
00027 set_component(MAJOR, "0");
00028 set_component(MINOR, "0");
00029 set_component(REVISION, "0");
00030 set_component(BUILD, "0");
00031 }
00032
00033 version::version(const string_array &version_info)
00034 : _components(new string_array(version_info))
00035 {
00036 for (int i = 0; i < _components->length(); i++) {
00037 if (!(*_components)[i]) {
00038
00039 (*_components)[i] = "0";
00040 }
00041 }
00042 }
00043
00044 version::version(const istring &formatted_string)
00045 : _components(new string_array)
00046 {
00047 istring verstring = formatted_string;
00048
00049 for (int j = 0; j < verstring.length(); j++) {
00050 if (verstring[j] == ',') verstring[j] = '.';
00051
00052 }
00053
00054 for (int i = 0; i < verstring.length(); i++) {
00055 int perindy = verstring.find('.', i);
00056 if (negative(perindy)) {
00057 if (verstring.length() - i > 0) {
00058
00059 *_components += verstring.substring(i, verstring.end());
00060 }
00061 break;
00062 }
00063
00064
00065 *_components += verstring.substring(i, perindy - 1);
00066 i = perindy;
00067
00068 }
00069 }
00070
00071 version::version(int maj, int min, int rev, int build)
00072 : _components(new string_array)
00073 {
00074 *this = version(isprintf("%u.%u.%u.%u", u_int(maj), u_int(min), u_int(rev),
00075 u_int(build)));
00076 }
00077
00078 version::version(const version &to_copy)
00079 : object_base(),
00080 packable(),
00081 _components(new string_array)
00082 { *this = to_copy; }
00083
00084 version::~version() { WHACK(_components); }
00085
00086 version &version::operator =(const version &to_copy)
00087 {
00088 if (this != &to_copy) *_components = *to_copy._components;
00089 return *this;
00090 }
00091
00092 istring version::text_form() const { return flex_text_form(); }
00093
00094 int version::components() const { return _components->length(); }
00095
00096 int version::v_major() const
00097 { return int(get_component(MAJOR).convert(0)); }
00098
00099 int version::v_minor() const
00100 { return int(get_component(MINOR).convert(0)); }
00101
00102 int version::v_revision() const
00103 { return int(get_component(REVISION).convert(0)); }
00104
00105 int version::v_build() const
00106 { return int(get_component(BUILD).convert(0)); }
00107
00108 istring version::get_component(int index) const
00109 {
00110 bounds_return(index, 0, _components->length() - 1, "0");
00111 return (*_components)[index];
00112 }
00113
00114 void version::set_component(int index, const istring &to_set)
00115 {
00116 if (_components->length() <= index)
00117 _components->resize(index + 1);
00118 if (to_set.t())
00119 (*_components)[index] = to_set;
00120 else
00121 (*_components)[index] = "0";
00122 }
00123
00124 bool version::operator == (const version &to_test) const
00125 { return *_components == *to_test._components; }
00126
00127 bool version::operator < (const version &to_test) const
00128 {
00129 if (v_major() < to_test.v_major()) return true;
00130 if (v_minor() < to_test.v_minor()) return true;
00131 if (v_revision() < to_test.v_revision()) return true;
00132 if (v_build() < to_test.v_build()) return true;
00133 return false;
00134 }
00135
00136 bool version::compatible(const version &to_test) const
00137 {
00138
00139 return (v_major() == to_test.v_major())
00140 && (v_minor() == to_test.v_minor())
00141 && (v_revision() == to_test.v_revision());
00142 }
00143
00144 bool version::bogus() const
00145 { return !v_major() && !v_minor() && !v_revision() && !v_build(); }
00146
00147 #define SEPARATE \
00148 if (style != DOTS) to_return += ", "; \
00149 else to_return += "."
00150
00151 istring version::flex_text_form(version_style style, int where) const
00152 {
00153
00154
00155 istring to_return;
00156
00157 if (style == DETAILED) to_return += "major ";
00158 istring temp = get_component(MAJOR);
00159 if (!temp) temp = "0";
00160 to_return += temp;
00161 if (where == MAJOR) return to_return;
00162 SEPARATE;
00163
00164 if (style == DETAILED) to_return += "minor ";
00165 temp = get_component(MINOR);
00166 if (!temp) temp = "0";
00167 to_return += temp;
00168 if (where == MINOR) return to_return;
00169 SEPARATE;
00170
00171 if (style == DETAILED) to_return += "revision ";
00172 temp = get_component(REVISION);
00173 if (!temp) temp = "0";
00174 to_return += temp;
00175 if (where == REVISION) return to_return;
00176 SEPARATE;
00177
00178 if (style == DETAILED) to_return += "build ";
00179 temp = get_component(BUILD);
00180 if (!temp) temp = "0";
00181 to_return += temp;
00182
00183
00184 if (where > BUILD) {
00185 for (int i = BUILD + 1; i < where; i++) {
00186 SEPARATE;
00187 if (style == DETAILED) to_return += isprintf("part_%d ", i + 1);
00188 temp = get_component(i);
00189 if (!temp) temp = "0";
00190 to_return += temp;
00191 }
00192 }
00193
00194 return to_return;
00195 }
00196
00197 version version::from_text(const istring &to_convert)
00198 { return version(to_convert); }
00199
00200 void version::pack(byte_array &target) const
00201 { _components->pack(target); }
00202
00203 bool version::unpack(byte_array &source)
00204 {
00205 if (!_components->unpack(source)) return false;
00206 return true;
00207 }
00208
00210
00211 #define VR_NEWLINE to_return += "\n"
00212
00213 version_record::~version_record()
00214 {}
00215
00216 istring version_record::text_form() const
00217 {
00218 istring to_return;
00219 to_return += "Description: ";
00220 to_return += description;
00221 VR_NEWLINE;
00222 to_return += "File Version: ";
00223 to_return += file_version.text_form();
00224 VR_NEWLINE;
00225 to_return += "Internal Name: ";
00226 to_return += internal_name;
00227 VR_NEWLINE;
00228 to_return += "Original Name: ";
00229 to_return += original_name;
00230 VR_NEWLINE;
00231 to_return += "Product Name: ";
00232 to_return += product_name;
00233 VR_NEWLINE;
00234 to_return += "Product Version: ";
00235 to_return += product_version.text_form();
00236 VR_NEWLINE;
00237 to_return += "Company Name: ";
00238 to_return += company_name;
00239 VR_NEWLINE;
00240 to_return += "Copyright: ";
00241 to_return += copyright;
00242 VR_NEWLINE;
00243 to_return += "Trademarks: ";
00244 to_return += trademarks;
00245 VR_NEWLINE;
00246
00247 return to_return;
00248 }
00249
00250
00251 #endif //VERSION_RECORD_IMPLEMENTATION_FILE
00252