Path.h
Go to the documentation of this file.
00001 //
00002 // Path.h
00003 //
00004 // $Id: //poco/1.3/Foundation/include/Poco/Path.h#3 $
00005 //
00006 // Library: Foundation
00007 // Package: Filesystem
00008 // Module:  Path
00009 //
00010 // Definition of the Path class.
00011 //
00012 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
00013 // and Contributors.
00014 //
00015 // Permission is hereby granted, free of charge, to any person or organization
00016 // obtaining a copy of the software and accompanying documentation covered by
00017 // this license (the "Software") to use, reproduce, display, distribute,
00018 // execute, and transmit the Software, and to prepare derivative works of the
00019 // Software, and to permit third-parties to whom the Software is furnished to
00020 // do so, all subject to the following:
00021 // 
00022 // The copyright notices in the Software and this entire statement, including
00023 // the above license grant, this restriction and the following disclaimer,
00024 // must be included in all copies of the Software, in whole or in part, and
00025 // all derivative works of the Software, unless such copies or derivative
00026 // works are solely in the form of machine-executable object code generated by
00027 // a source language processor.
00028 // 
00029 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00030 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00031 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00032 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00033 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00034 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00035 // DEALINGS IN THE SOFTWARE.
00036 //
00037 
00038 
00039 #ifndef Foundation_Path_INCLUDED
00040 #define Foundation_Path_INCLUDED
00041 
00042 
00043 #include "Poco/Foundation.h"
00044 #include <vector>
00045 
00046 
00047 namespace Poco {
00048 
00049 
00050 class Foundation_API Path
00061 {
00062 public:
00063         enum Style
00064         {
00065                 PATH_UNIX,    
00066                 PATH_WINDOWS, 
00067                 PATH_VMS,     
00068                 PATH_NATIVE,  
00069                 PATH_GUESS    
00070         };
00071         
00072         typedef std::vector<std::string> StringVec;
00073 
00074         Path();
00076 
00077         Path(bool absolute);
00079 
00080         Path(const char* path);
00082 
00083         Path(const char* path, Style style);
00085 
00086         Path(const std::string& path);
00088 
00089         Path(const std::string& path, Style style);
00091 
00092         Path(const Path& path);
00094 
00095         Path(const Path& parent, const std::string& fileName);
00098 
00099         Path(const Path& parent, const char* fileName);
00102 
00103         Path(const Path& parent, const Path& relative);
00107 
00108         ~Path();
00110                 
00111         Path& operator = (const Path& path);
00113                 
00114         Path& operator = (const std::string& path);
00116 
00117         Path& operator = (const char* path);
00119 
00120         void swap(Path& path);
00122 
00123         Path& assign(const std::string& path);
00125                 
00126         Path& assign(const std::string& path, Style style);
00128 
00129         Path& assign(const Path& path);
00131                 
00132         Path& assign(const char* path);
00134 
00135         std::string toString() const;
00137                 
00138         std::string toString(Style style) const;
00140                 
00141         Path& parse(const std::string& path);
00143 
00144         Path& parse(const std::string& path, Style style);
00146 
00147         bool tryParse(const std::string& path);
00153 
00154         bool tryParse(const std::string& path, Style style);
00160 
00161         Path& parseDirectory(const std::string& path);
00164 
00165         Path& parseDirectory(const std::string& path, Style style);
00168 
00169         Path& makeDirectory();
00173 
00174         Path& makeFile();
00177 
00178         Path& makeParent();
00180                 
00181         Path& makeAbsolute();
00184 
00185         Path& makeAbsolute(const Path& base);
00188 
00189         Path& append(const Path& path);
00191                 
00192         Path& resolve(const Path& path);
00197 
00198         bool isAbsolute() const;
00200                 
00201         bool isRelative() const;
00203         
00204         bool isDirectory() const;
00207                 
00208         bool isFile() const;
00211         
00212         void setNode(const std::string& node);
00216                 
00217         const std::string& getNode() const;
00219                 
00220         void setDevice(const std::string& device);
00224                 
00225         const std::string& getDevice() const;
00227         
00228         int depth() const;
00230 
00231         const std::string& directory(int n) const;
00234                 
00235         const std::string& operator [] (int n) const;
00238                 
00239         void pushDirectory(const std::string& dir);
00241                 
00242         void popDirectory();
00244                 
00245         void setFileName(const std::string& name);
00247                 
00248         const std::string& getFileName() const;
00250 
00251         void setBaseName(const std::string& name);
00254 
00255         std::string getBaseName() const;
00258 
00259         void setExtension(const std::string& extension);
00261                                 
00262         std::string getExtension() const;
00264                 
00265         const std::string& version() const;
00267                 
00268         void clear();
00270 
00271         Path parent() const;
00274                 
00275         Path absolute() const;
00278 
00279         Path absolute(const Path& base) const;
00282 
00283         static Path forDirectory(const std::string& path);
00285 
00286         static Path forDirectory(const std::string& path, Style style);
00288 
00289         static char separator();
00296                 
00297         static char pathSeparator();
00304                 
00305         static std::string current();
00307                 
00308         static std::string home();
00310                 
00311         static std::string temp();
00313                 
00314         static std::string null();
00316                 
00317         static std::string expand(const std::string& path);
00322 
00323         static void listRoots(std::vector<std::string>& roots);
00328                 
00329         static bool find(StringVec::const_iterator it, StringVec::const_iterator end, const std::string& name, Path& path);
00336 
00337         static bool find(const std::string& pathList, const std::string& name, Path& path);
00345                 
00346         static std::string transcode(const std::string& path);
00356 
00357 protected:
00358         void parseUnix(const std::string& path);
00359         void parseWindows(const std::string& path);
00360         void parseVMS(const std::string& path);
00361         void parseGuess(const std::string& path);
00362         std::string buildUnix() const;
00363         std::string buildWindows() const;
00364         std::string buildVMS() const;
00365 
00366 private:
00367         std::string _node;
00368         std::string _device;
00369         std::string _name;
00370         std::string _version;
00371         StringVec   _dirs;
00372         bool        _absolute;
00373 };
00374 
00375 
00376 //
00377 // inlines
00378 //
00379 inline bool Path::isAbsolute() const
00380 {
00381         return _absolute;
00382 }
00383 
00384         
00385 inline bool Path::isRelative() const
00386 {
00387         return !_absolute;
00388 }
00389 
00390 
00391 inline bool Path::isDirectory() const
00392 {
00393         return _name.empty();
00394 }
00395 
00396 
00397 inline bool Path::isFile() const
00398 {
00399         return !_name.empty();
00400 }
00401 
00402 
00403 inline Path& Path::parse(const std::string& path)
00404 {
00405         return assign(path);
00406 }
00407 
00408 
00409 inline Path& Path::parse(const std::string& path, Style style)
00410 {
00411         return assign(path, style);
00412 }
00413 
00414 
00415 inline const std::string& Path::getNode() const
00416 {
00417         return _node;
00418 }
00419 
00420 
00421 inline const std::string& Path::getDevice() const
00422 {
00423         return _device;
00424 }
00425 
00426 
00427 inline const std::string& Path::getFileName() const
00428 {
00429         return _name;
00430 }
00431 
00432 
00433 inline int Path::depth() const
00434 {
00435         return int(_dirs.size());
00436 }
00437 
00438 
00439 inline const std::string& Path::version() const
00440 {
00441         return _version;
00442 }
00443 
00444 
00445 inline Path Path::forDirectory(const std::string& path)
00446 {
00447         Path p;
00448         return p.parseDirectory(path);
00449 }
00450         
00451 
00452 inline Path Path::forDirectory(const std::string& path, Style style)
00453 {
00454         Path p;
00455         return p.parseDirectory(path, style);
00456 }
00457 
00458 
00459 inline char Path::separator()
00460 {
00461 #if defined(POCO_OS_FAMILY_VMS)
00462         return '.';
00463 #elif defined(POCO_OS_FAMILY_WINDOWS)
00464         return '\\';
00465 #else
00466         return '/';
00467 #endif
00468 }
00469 
00470 
00471 inline char Path::pathSeparator()
00472 {
00473 #if defined(POCO_OS_FAMILY_VMS)
00474         return ',';
00475 #elif defined(POCO_OS_FAMILY_WINDOWS)
00476         return ';';
00477 #else
00478         return ':';
00479 #endif
00480 }
00481 
00482 
00483 inline void swap(Path& p1, Path& p2)
00484 {
00485         p1.swap(p2);
00486 }
00487 
00488 
00489 } // namespace Poco
00490 
00491 
00492 #endif // Foundation_Path_INCLUDED


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:19