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 #include <time.h>
29 
30 namespace ept {
31 namespace popcon {
32 
36 class Path
37 {
38 public:
39  static std::string scores();
40  static std::string scoresIndex();
41  static std::string userScores();
42  static std::string userScoresIndex();
43 
44  static std::string popconSourceDir();
45  static std::string popconIndexDir();
46  static std::string popconUserSourceDir();
47  static std::string popconUserIndexDir();
48 
49  // Directory where Popcon source data is found
50  static void setPopconSourceDir( const std::string &s );
51 
52  // Directory where Popcon indexes are kept
53  static void setPopconIndexDir( const std::string &s );
54 
55  // User-specific directory for Popcon source data
56  static void setPopconUserSourceDir( const std::string &s );
57 
58  // User-specific directory for Popcon index data
59  static void setPopconUserIndexDir( const std::string &s );
60 
61  static int access( const std::string &, int );
62  static time_t timestamp( const std::string& );
63 
64  // RAII-style classes to temporarily override directories
66  {
67  std::string old;
68  public:
69  OverridePopconSourceDir(const std::string& path) : old(Path::popconSourceDir())
70  {
72  }
74  };
76  {
77  std::string old;
78  public:
79  OverridePopconIndexDir(const std::string& path) : old(Path::popconIndexDir())
80  {
82  }
84  };
86  {
87  std::string old;
88  public:
89  OverridePopconUserSourceDir(const std::string& path) : old(Path::popconUserSourceDir())
90  {
92  }
94  };
96  {
97  std::string old;
98  public:
99  OverridePopconUserIndexDir(const std::string& path) : old(Path::popconUserIndexDir())
100  {
102  }
104  };
105 protected:
106  static Path *s_instance;
107  static Path &instance();
108 
109  // Directory where Popcon source data is found
110  std::string m_popconSourceDir;
111 
112  // Directory where Popcon indexes are kept
113  std::string m_popconIndexDir;
114 
115  // User-specific directory for Popcon source data
117 
118  // User-specific directory for Popcon index data
119  std::string m_popconUserIndexDir;
120 };
121 
122 }
123 }
124 
125 // vim:set ts=4 sw=4:
126 #endif
OverridePopconSourceDir(const std::string &path)
Definition: popcon/maint/path.h:69
static std::string popconUserIndexDir()
Definition: popcon/maint/path.cc:90
Definition: popcon/maint/path.h:65
Singleton class to configure and access the various Popcon paths.
Definition: popcon/maint/path.h:36
Definition: popcon/maint/path.h:95
static std::string popconUserSourceDir()
Definition: popcon/maint/path.cc:89
static void setPopconIndexDir(const std::string &s)
Definition: popcon/maint/path.cc:74
OverridePopconUserSourceDir(const std::string &path)
Definition: popcon/maint/path.h:89
static int access(const std::string &, int)
Definition: popcon/maint/path.cc:62
static Path & instance()
Definition: popcon/maint/path.cc:51
static std::string scoresIndex()
Definition: popcon/maint/path.cc:96
std::string m_popconSourceDir
Definition: popcon/maint/path.h:110
Definition: apt.cc:42
std::string m_popconUserIndexDir
Definition: popcon/maint/path.h:119
Definition: popcon/maint/path.h:85
~OverridePopconIndexDir()
Definition: popcon/maint/path.h:83
static std::string scores()
Definition: popcon/maint/path.cc:92
std::string m_popconUserSourceDir
Definition: popcon/maint/path.h:116
OverridePopconIndexDir(const std::string &path)
Definition: popcon/maint/path.h:79
static std::string popconSourceDir()
Definition: popcon/maint/path.cc:87
~OverridePopconSourceDir()
Definition: popcon/maint/path.h:73
Definition: popcon/maint/path.h:75
OverridePopconUserIndexDir(const std::string &path)
Definition: popcon/maint/path.h:99
static std::string userScoresIndex()
Definition: popcon/maint/path.cc:104
~OverridePopconUserIndexDir()
Definition: popcon/maint/path.h:103
std::string m_popconIndexDir
Definition: popcon/maint/path.h:113
static Path * s_instance
Definition: popcon/maint/path.h:106
static void setPopconUserSourceDir(const std::string &s)
Definition: popcon/maint/path.cc:78
~OverridePopconUserSourceDir()
Definition: popcon/maint/path.h:93
static std::string userScores()
Definition: popcon/maint/path.cc:100
static void setPopconSourceDir(const std::string &s)
Definition: popcon/maint/path.cc:70
static time_t timestamp(const std::string &)
Definition: popcon/maint/path.cc:66
static std::string popconIndexDir()
Definition: popcon/maint/path.cc:88
static void setPopconUserIndexDir(const std::string &s)
Definition: popcon/maint/path.cc:82