contrib/oxl/mvl/FileNameGenerator.h
Go to the documentation of this file.
00001 // This is oxl/mvl/FileNameGenerator.h
00002 #ifndef FileNameGenerator_h_
00003 #define FileNameGenerator_h_
00004 //:
00005 // \file
00006 // \author
00007 //     Andrew W. Fitzgibbon, Oxford RRG, 25 Feb 98
00008 //
00009 // \verbatim
00010 //  Modifications
00011 //   Dec.2001 - Ported to vxl by Peter Vanroose
00012 //   10 Sep. 2004 Peter Vanroose  Inlined all 1-line methods in class decl
00013 // \endverbatim
00014 //
00015 //-----------------------------------------------------------------------------
00016 
00017 #include <vcl_string.h>
00018 #include <mvl/FileNameGeneratorBase.h>
00019 
00020 class FileNameGenerator
00021 {
00022   FileNameGeneratorBase* fng_;
00023   vcl_string subdir_;
00024   vcl_string suffix_;
00025 
00026   // default copy ctor OK
00027  public:
00028   FileNameGenerator(FileNameGeneratorBase* fng,
00029                     vcl_string const& suffix)
00030   : fng_(fng), subdir_(), suffix_(suffix)
00031   {
00032   }
00033 
00034   FileNameGenerator(FileNameGeneratorBase* fng,
00035                     const char* suffix)
00036   : fng_(fng), subdir_(), suffix_(suffix)
00037   {
00038   }
00039 
00040   FileNameGenerator(FileNameGeneratorBase* fng,
00041                     vcl_string const& subdir,
00042                     vcl_string const& suffix)
00043   : fng_(fng), subdir_(), suffix_(suffix)
00044   {
00045     if (fng->use_subdirs) subdir_ = subdir;
00046   }
00047 
00048   FileNameGenerator(FileNameGeneratorBase* fng,
00049                     const char* subdir,
00050                     const char* suffix)
00051   : fng_(fng), subdir_(), suffix_(suffix)
00052   {
00053     if (fng->use_subdirs) subdir_ = subdir;
00054   }
00055 
00056   FileNameGeneratorBase* get_base() const { return fng_; }
00057   vcl_string get_subdir() const { return subdir_; }
00058   vcl_string get_suffix() const { return suffix_; }
00059   bool uses_subdir() const { return subdir_.c_str()[0]!='\0'; }
00060 
00061   vcl_string subdir_name() const { return fng_->dirname() + "/" + subdir_; }
00062 
00063   vcl_string name() {
00064     return (subdir_.c_str()[0]=='\0') ?
00065       fng_->basename() + suffix_    :
00066       fng_->basename(subdir_.c_str()) + suffix_;
00067   }
00068 
00069   vcl_string frame_name(int i1) {
00070     return (subdir_.c_str()[0]=='\0') ?
00071       fng_->frame_basename(i1) + suffix_ :
00072       fng_->frame_basename(subdir_.c_str(), i1) + suffix_;
00073   }
00074 
00075   vcl_string pair_name(int i1, int i2) {
00076     return (subdir_.c_str()[0]=='\0') ?
00077       fng_->pair_basename(i1, i2) + suffix_ :
00078       fng_->pair_basename(subdir_.c_str(), i1, i2) + suffix_;
00079   }
00080 
00081   vcl_string triplet_name(int i1, int i2, int i3) {
00082     return (subdir_.c_str()[0]=='\0') ?
00083       fng_->triplet_basename(i1, i2, i3) + suffix_ :
00084       fng_->triplet_basename(subdir_.c_str(), i1, i2, i3) + suffix_;
00085   }
00086 };
00087 
00088 #endif // FileNameGenerator_h_