head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.40; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.57; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.04; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.00; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# sg_path.cxx

    00001 // sg_path.cxx -- routines to abstract out path separator differences
    00002 //               between MacOS and the rest of the world
    00003 //
    00004 // Written by Curtis L. Olson, started April 1999.
    00005 //
    00006 // Copyright (C) 1999  Curtis L. Olson - curt@@flightgear.org
    00007 //
    00008 // This library is free software; you can redistribute it and/or
    00009 // modify it under the terms of the GNU Library General Public
    00010 // License as published by the Free Software Foundation; either
    00011 // version 2 of the License, or (at your option) any later version.
    00012 //
    00013 // This library is distributed in the hope that it will be useful,
    00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00016 // Library General Public License for more details.
    00017 //
    00018 // You should have received a copy of the GNU Library General Public
    00019 // License along with this library; if not, write to the
    00020 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00021 // Boston, MA  02111-1307, USA.
    00022 //
    00023 // $Id: sg_path.cxx,v 1.4 2002/02/04 20:23:41 curt Exp $
    00024
    00025
    00026 #include <simgear_config.h>
    00027 #include <stdio.h>
    00028
    00029 #include "sg_path.hxx"
    00030
    00031
    00032 // If Unix, replace all ":" with "/".  If MacOS, replace all "/" with
    00033 // ":" it should go without saying that neither of these characters
    00034 // should be used in file or directory names.  In windoze, allow the
    00035 // second character to be a ":" for things like c:\foo\bar
    00036
    00037 void
    00038 SGPath::fix()
    00039 {
    00040     for ( string::size_type i = 0; i < path.size(); ++i ) {
    00041 #if defined( WIN32 )
    00042         // for windoze, don't replace the ":" for the second character
    00043         if ( i == 1 ) {
    00044             continue;
    00045         }
    00046 #endif
    00047         if ( path[i] == SG_BAD_PATH_SEP ) {
    00048             path[i] = SG_PATH_SEP;
    00049         }
    00050     }
    00051 }
    00052
    00053
    00054 // default constructor
    00055 SGPath::SGPath()
    00056     : path("")
    00057 {
    00058 }
    00059
    00060
    00061 // create a path based on "path"
    00062 SGPath::SGPath( const std::string& p )
    00063     : path(p)
    00064 {
    00065     fix();
    00066 }
    00067
    00068
    00069 // destructor
    00070 SGPath::~SGPath() {
    00071 }
    00072
    00073
    00074 // set path
    00075 void SGPath::set( const string& p ) {
    00076     path = p;
    00077     fix();
    00078 }
    00079
    00080
    00081 // append another piece to the existing path
    00082 void SGPath::append( const string& p ) {
    00083     if ( path.size() == 0 ) {
    00084         path = p;
    00085     } else {
    00086         if ( p[0] != SG_PATH_SEP ) {
    00087             path += SG_PATH_SEP;
    00088         }
    00089         path += p;
    00090     }
    00091     fix();
    00092 }
    00093
    00094
    00095 // concatenate a string to the end of the path without inserting a
    00096 // path separator
    00097 void SGPath::concat( const string& p ) {
    00098     if ( path.size() == 0 ) {
    00099         path = p;
    00100     } else {
    00101         path += p;
    00102     }
    00103     fix();
    00104 }
    00105
    00106
    00107 // get the directory part of the path.
    00108 string SGPath::dir() {
    00109     int index = path.rfind(SG_PATH_SEP);
    00110     if (index >= 0) {
    00111         return path.substr(0, index);
    00112     } else {
    00113         return "";
    00114     }
    00115 }
    00116
    00117 bool SGPath::exists() const {
    00118     FILE* fp = fopen( path.c_str(), "r");
    00119     if (fp == 0) {
    00120         return false;
    00121     }
    00122     fclose(fp);
    00123     return true;
    00124 }

@ 1.3 log @Oops, try again. @ text @d133 1 a133 1