Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

path.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++ -*-
00002    
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2003 Koblenz University
00006    $Id: path.cpp,v 1.2 2003/05/19 21:32:40 fruit Exp $
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; version 2 of the License.
00011   
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016  
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 */
00021 #include "path.h"
00022 
00023 #include <boost/tokenizer.hpp>
00024 
00025 using namespace std;
00026 using namespace salt;
00027 
00028 Path::Path(const std::string &path)
00029 {
00030     Set(path);
00031 }
00032 
00033 void Path::Set(const std::string &path)
00034 {
00035     if (path[0] == '/' || path[0] == '\\')
00036     {
00037         mIsAbsolute = true;
00038     }
00039     else
00040     {
00041         mIsAbsolute = false;
00042     }
00043 
00044     Tokenize(path);
00045 }
00046 
00047 std::string Path::GetCleanPath(const std::string &sep) const
00048 {
00049     string path;
00050 
00051     if (mIsAbsolute)
00052     {
00053         path += sep;
00054     }
00055 
00056     unsigned int count = 0;
00057     for (TStringList::const_iterator i = mPathComponents.begin(); i != mPathComponents.end(); ++i)
00058     {
00059         path += (*i);
00060         ++count;
00061         if ( count != mPathComponents.size() )
00062         {
00063             path += sep;
00064         }
00065     }
00066 
00067     return path;
00068 }
00069 
00070 bool Path::IsAbsolute() const
00071 {
00072     return mIsAbsolute;
00073 }
00074 
00075 bool Path::IsEmpty() const
00076 {
00077     return mPathComponents.empty();
00078 }
00079 
00080 const std::string& Path::Front() const
00081 {
00082     return mPathComponents.front();
00083 }
00084 
00085 void Path::PopFront()
00086 {
00087     mIsAbsolute = false;
00088     mPathComponents.pop_front();
00089 }
00090 
00091 const std::string& Path::Back() const
00092 {
00093     return mPathComponents.back();
00094 }
00095 
00096 void Path::PopBack()
00097 {
00098     mPathComponents.pop_back();
00099 }
00100 
00101 void Path::Tokenize(const std::string &path)
00102 {
00103     typedef boost::tokenizer<boost::char_separator<char> > TTokenizer;
00104     boost::char_separator<char> sep("/\\");
00105     TTokenizer  tokens(path, sep);
00106 
00107     for (TTokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i)
00108     {
00109         mPathComponents.push_back(*i);
00110     }
00111 }

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4