libept
popcon/maint/path.h
Go to the documentation of this file.
1 // -*- mode: c++; indent-tabs-mode: t -*-
6 /*
7  * Copyright (C) 2005,2006,2007 Enrico Zini <enrico@debian.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef EPT_POPCON_PATH_H
25 #define EPT_POPCON_PATH_H
26 
27 #include <string>
28 
29 struct stat;
30 
31 namespace ept {
32 namespace popcon {
33 
37 class Path
38 {
39 public:
40  static std::string scores();
41  static std::string scoresIndex();
42  static std::string userScores();
43  static std::string userScoresIndex();
44 
45  static std::string popconSourceDir();
46  static std::string popconIndexDir();
47  static std::string popconUserSourceDir();
48  static std::string popconUserIndexDir();
49 
50  // Directory where Popcon source data is found
51  static void setPopconSourceDir( const std::string &s );
52 
53  // Directory where Popcon indexes are kept
54  static void setPopconIndexDir( const std::string &s );
55 
56  // User-specific directory for Popcon source data
57  static void setPopconUserSourceDir( const std::string &s );
58 
59  // User-specific directory for Popcon index data
60  static void setPopconUserIndexDir( const std::string &s );
61 
62  static int access( const std::string &, int );
63  static time_t timestamp( const std::string& );
64 
65  // RAII-style classes to temporarily override directories
67  {
68  std::string old;
69  public:
70  OverridePopconSourceDir(const std::string& path) : old(Path::popconSourceDir())
71  {
73  }
75  };
77  {
78  std::string old;
79  public:
80  OverridePopconIndexDir(const std::string& path) : old(Path::popconIndexDir())
81  {
83  }
85  };
87  {
88  std::string old;
89  public:
90  OverridePopconUserSourceDir(const std::string& path) : old(Path::popconUserSourceDir())
91  {
93  }
95  };
97  {
98  std::string old;
99  public:
100  OverridePopconUserIndexDir(const std::string& path) : old(Path::popconUserIndexDir())
101  {
103  }
105  };
106 protected:
107  static Path *s_instance;
108  static Path &instance();
109 
110  // Directory where Popcon source data is found
111  std::string m_popconSourceDir;
112 
113  // Directory where Popcon indexes are kept
114  std::string m_popconIndexDir;
115 
116  // User-specific directory for Popcon source data
118 
119  // User-specific directory for Popcon index data
120  std::string m_popconUserIndexDir;
121 };
122 
123 }
124 }
125 
126 // vim:set ts=4 sw=4:
127 #endif