00001 /* 00002 Copyright (C) 2001-2006, William Joseph. 00003 All Rights Reserved. 00004 00005 This file is part of GtkRadiant. 00006 00007 GtkRadiant is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 GtkRadiant 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 GtkRadiant; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #if !defined(INCLUDED_FS_PATH_H) 00023 #define INCLUDED_FS_PATH_H 00024 00025 #include "stream/stringstream.h" 00026 00031 class UnixPath { 00032 StringBuffer m_string; 00033 00034 void check_separator() { 00035 if (!empty() && m_string.back() != '/') { 00036 m_string.push_back('/'); 00037 } 00038 } 00039 00040 public: 00042 UnixPath(const char* root) 00043 : m_string(root) { 00044 check_separator(); 00045 } 00046 00047 bool empty() const { 00048 return m_string.empty(); 00049 } 00050 00051 const char* c_str() const { 00052 return m_string.c_str(); 00053 } 00054 00056 void push(const char* name) { 00057 m_string.push_string(name); 00058 check_separator(); 00059 } 00061 void push(const std::string& name) { 00062 m_string.push_string(name.c_str()); 00063 check_separator(); 00064 } 00066 void push(const char* first, const char* last) { 00067 m_string.push_range(first, last); 00068 check_separator(); 00069 } 00071 void push_filename(const char* name) { 00072 m_string.push_string(name); 00073 } 00075 void push_filename(const std::string& name) { 00076 m_string.push_string(name.c_str()); 00077 } 00079 void pop() { 00080 if (m_string.back() == '/') { 00081 m_string.pop_back(); 00082 } 00083 while (!empty() && m_string.back() != '/') { 00084 m_string.pop_back(); 00085 } 00086 } 00087 }; 00088 00089 #endif