00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "softFilename.h"
00016
00017 #include "pnotify.h"
00018
00019
00020
00021
00022
00023
00024 SoftFilename::
00025 SoftFilename(const string &dirname, const string &filename) :
00026 _dirname(dirname),
00027 _filename(filename)
00028 {
00029 _has_version = false;
00030 _major = 0;
00031 _minor = 0;
00032 _in_cvs = false;
00033 _wants_cvs = false;
00034 _use_count = 0;
00035
00036 _base = _filename;
00037
00038
00039
00040 size_t dot = _filename.find('.');
00041 while (dot != string::npos) {
00042 size_t m = dot + 1;
00043 const char *fstr = _filename.c_str();
00044 char *endptr;
00045
00046 int major = strtol(fstr + m , &endptr, 10);
00047 if (endptr != fstr + m && *endptr == '-') {
00048
00049 m = (endptr - fstr) + 1;
00050 int minor = strtol(fstr + m, &endptr, 10);
00051 if (endptr != fstr + m && (*endptr == '.' || *endptr == '\0')) {
00052
00053 _has_version = true;
00054 _base = _filename.substr(0, dot + 1);
00055 _major = major;
00056 _minor = minor;
00057 _ext = endptr;
00058 return;
00059 }
00060 }
00061
00062
00063 dot = _filename.find('.', dot + 1);
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072 SoftFilename::
00073 SoftFilename(const SoftFilename ©) :
00074 _dirname(copy._dirname),
00075 _filename(copy._filename),
00076 _has_version(copy._has_version),
00077 _base(copy._base),
00078 _major(copy._major),
00079 _minor(copy._minor),
00080 _ext(copy._ext),
00081 _in_cvs(copy._in_cvs),
00082 _wants_cvs(copy._wants_cvs),
00083 _use_count(copy._use_count)
00084 {
00085 }
00086
00087
00088
00089
00090
00091
00092 void SoftFilename::
00093 operator = (const SoftFilename ©) {
00094 _dirname = copy._dirname;
00095 _filename = copy._filename;
00096 _has_version = copy._has_version;
00097 _base = copy._base;
00098 _major = copy._major;
00099 _minor = copy._minor;
00100 _ext = copy._ext;
00101 _in_cvs = copy._in_cvs;
00102 _wants_cvs = copy._wants_cvs;
00103 _use_count = copy._use_count;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112 const string &SoftFilename::
00113 get_dirname() const {
00114 return _dirname;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 const string &SoftFilename::
00124 get_filename() const {
00125 return _filename;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 bool SoftFilename::
00135 has_version() const {
00136 return _has_version;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145 string SoftFilename::
00146 get_1_0_filename() const {
00147 nassertr(_has_version, string());
00148 return _base + "1-0" + _ext;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 const string &SoftFilename::
00158 get_base() const {
00159 nassertr(_has_version, _filename);
00160 return _base;
00161 }
00162
00163
00164
00165
00166
00167
00168 int SoftFilename::
00169 get_major() const {
00170 nassertr(_has_version, 0);
00171 return _major;
00172 }
00173
00174
00175
00176
00177
00178
00179 int SoftFilename::
00180 get_minor() const {
00181 nassertr(_has_version, 0);
00182 return _minor;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 const string &SoftFilename::
00192 get_extension() const {
00193 nassertr(_has_version, _ext);
00194 return _ext;
00195 }
00196
00197
00198
00199
00200
00201
00202 string SoftFilename::
00203 get_non_extension() const {
00204 nassertr(_has_version, _filename);
00205 nassertr(_ext.length() < _filename.length(), _filename);
00206 return _filename.substr(0, _filename.length() - _ext.length());
00207 }
00208
00209
00210
00211
00212
00213
00214
00215 bool SoftFilename::
00216 is_1_0() const {
00217 nassertr(_has_version, false);
00218 return (_major == 1 && _minor == 0);
00219 }
00220
00221
00222
00223
00224
00225
00226 void SoftFilename::
00227 make_1_0() {
00228 _has_version = true;
00229 _major = 1;
00230 _minor = 0;
00231 _filename = get_1_0_filename();
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241 bool SoftFilename::
00242 is_same_file(const SoftFilename &other) const {
00243 return _base == other._base && _ext == other._ext;
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 bool SoftFilename::
00256 operator < (const SoftFilename &other) const {
00257 if (_base != other._base) {
00258 return _base < other._base;
00259 }
00260
00261 if (_has_version != other._has_version) {
00262
00263
00264 return _has_version < other._has_version;
00265 }
00266
00267 if (_has_version) {
00268 if (_major != other._major) {
00269 return _major > other._major;
00270 }
00271 if (_minor != other._minor) {
00272 return _minor > other._minor;
00273 }
00274 }
00275
00276 return false;
00277 }
00278
00279
00280
00281
00282
00283
00284
00285 void SoftFilename::
00286 set_in_cvs(bool in_cvs) {
00287 _in_cvs = in_cvs;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296 bool SoftFilename::
00297 get_in_cvs() const {
00298 return _in_cvs;
00299 }
00300
00301
00302
00303
00304
00305
00306
00307 void SoftFilename::
00308 set_wants_cvs(bool wants_cvs) {
00309 _wants_cvs = wants_cvs;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318 bool SoftFilename::
00319 get_wants_cvs() const {
00320 return _wants_cvs;
00321 }
00322
00323
00324
00325
00326
00327
00328
00329 void SoftFilename::
00330 increment_use_count() {
00331 _use_count++;
00332 }
00333
00334
00335
00336
00337
00338
00339
00340 int SoftFilename::
00341 get_use_count() const {
00342 return _use_count;
00343 }