libept
|
00001 // -*- mode: c++; indent-tabs-mode: t -*- 00006 /* 00007 * Copyright (C) 2005,2006,2007 Enrico Zini <enrico@debian.org> 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #ifndef EPT_POPCON_PATH_H 00025 #define EPT_POPCON_PATH_H 00026 00027 #include <string> 00028 00029 struct stat; 00030 00031 namespace ept { 00032 namespace popcon { 00033 00037 class Path 00038 { 00039 public: 00040 static std::string scores(); 00041 static std::string scoresIndex(); 00042 static std::string userScores(); 00043 static std::string userScoresIndex(); 00044 00045 static std::string popconSourceDir(); 00046 static std::string popconIndexDir(); 00047 static std::string popconUserSourceDir(); 00048 static std::string popconUserIndexDir(); 00049 00050 // Directory where Popcon source data is found 00051 static void setPopconSourceDir( const std::string &s ); 00052 00053 // Directory where Popcon indexes are kept 00054 static void setPopconIndexDir( const std::string &s ); 00055 00056 // User-specific directory for Popcon source data 00057 static void setPopconUserSourceDir( const std::string &s ); 00058 00059 // User-specific directory for Popcon index data 00060 static void setPopconUserIndexDir( const std::string &s ); 00061 00062 static int access( const std::string &, int ); 00063 static time_t timestamp( const std::string& ); 00064 00065 // RAII-style classes to temporarily override directories 00066 class OverridePopconSourceDir 00067 { 00068 std::string old; 00069 public: 00070 OverridePopconSourceDir(const std::string& path) : old(Path::popconSourceDir()) 00071 { 00072 Path::setPopconSourceDir(path); 00073 } 00074 ~OverridePopconSourceDir() { Path::setPopconSourceDir(old); } 00075 }; 00076 class OverridePopconIndexDir 00077 { 00078 std::string old; 00079 public: 00080 OverridePopconIndexDir(const std::string& path) : old(Path::popconIndexDir()) 00081 { 00082 Path::setPopconIndexDir(path); 00083 } 00084 ~OverridePopconIndexDir() { Path::setPopconIndexDir(old); } 00085 }; 00086 class OverridePopconUserSourceDir 00087 { 00088 std::string old; 00089 public: 00090 OverridePopconUserSourceDir(const std::string& path) : old(Path::popconUserSourceDir()) 00091 { 00092 Path::setPopconUserSourceDir(path); 00093 } 00094 ~OverridePopconUserSourceDir() { Path::setPopconUserSourceDir(old); } 00095 }; 00096 class OverridePopconUserIndexDir 00097 { 00098 std::string old; 00099 public: 00100 OverridePopconUserIndexDir(const std::string& path) : old(Path::popconUserIndexDir()) 00101 { 00102 Path::setPopconUserIndexDir(path); 00103 } 00104 ~OverridePopconUserIndexDir() { Path::setPopconUserIndexDir(old); } 00105 }; 00106 protected: 00107 static Path *s_instance; 00108 static Path &instance(); 00109 00110 // Directory where Popcon source data is found 00111 std::string m_popconSourceDir; 00112 00113 // Directory where Popcon indexes are kept 00114 std::string m_popconIndexDir; 00115 00116 // User-specific directory for Popcon source data 00117 std::string m_popconUserSourceDir; 00118 00119 // User-specific directory for Popcon index data 00120 std::string m_popconUserIndexDir; 00121 }; 00122 00123 } 00124 } 00125 00126 // vim:set ts=4 sw=4: 00127 #endif