File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,17 @@ class FileSpec
2323 void setType (FileType type);
2424 Directory getDir () const ;
2525 void setDir (Directory dir);
26+ void setPath (std::string& base, std::string param, std::string env_name);
27+ void getPath (std::string& full_name);
28+ std::string getPrefix () {
29+ return prefix_;
30+ }
2631
2732private:
2833 Directory dir_;
2934 FileType type_;
3035 std::string name_;
36+ std::string prefix_ {" " };
3137 std::string md5_;
3238 boost::posix_time::ptime date_;
3339 int size_;
Original file line number Diff line number Diff line change 11#include < vb_util_lib/file_spec.h>
2+ #include < cstdlib>
23
34const boost::posix_time::ptime& FileSpec::getDate () const {
45 return date_;
@@ -47,3 +48,61 @@ FileSpec::Directory FileSpec::getDir() const {
4748void FileSpec::setDir (FileSpec::Directory dir) {
4849 dir_ = dir;
4950}
51+
52+ void FileSpec::setPath (std::string& base, std::string param, std::string env_name) {
53+ char sep = ' /' ;
54+ std::string base_dir = " " ;
55+ prefix_ = " " ;
56+ name_ = " " ;
57+
58+ size_t i = base.rfind (sep, base.length ());
59+ if (i != std::string::npos)
60+ {
61+ name_ = base.substr (i+1 , base.length () - i);
62+ base_dir = base.substr (0 , i+1 );
63+ }
64+ else
65+ {
66+ name_= base;
67+ base_dir = " " ;
68+ }
69+
70+ if (base_dir.length () != 0 && base_dir.at (0 ) == sep)
71+ {
72+ // Absolute path name
73+ prefix_ = base_dir;
74+ return ;
75+ }
76+
77+ // Append the separator to the base_dir
78+ if (base_dir.length () > 0 && base_dir.at (base_dir.length ()-1 ) != sep)
79+ {
80+ base_dir += " /" ;
81+ }
82+
83+ if (param.length () > 0 )
84+ {
85+ // use the parameter as the directory name.
86+ prefix_ = param;
87+ } else if (env_name.length () > 0 )
88+ {
89+ // use the environment variable
90+ if (const char * env_p = std::getenv (env_name.c_str ()))
91+ {
92+ prefix_ = env_p;
93+ }
94+ }
95+
96+ // Append the separator to the prefix
97+ if (prefix_.length () > 0 && prefix_.at (prefix_.length ()-1 ) != sep)
98+ {
99+ prefix_ += " /" ;
100+ }
101+ prefix_ += base_dir;
102+
103+ return ;
104+ }
105+
106+ void FileSpec::getPath (std::string& full_name) {
107+ full_name = prefix_ + name_;
108+ }
You can’t perform that action at this time.
0 commit comments