libsaria: Pass around more const strings
This allows me to pass them by reference, it should be a bit more efficient. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
0b9beac1c3
commit
b7a21789b6
|
@ -12,19 +12,18 @@ enum DataState {
|
|||
|
||||
namespace libsaria
|
||||
{
|
||||
bool exists(string);
|
||||
bool exists(const string &);
|
||||
void list_dir(string &, list<string> &);
|
||||
|
||||
namespace app
|
||||
{
|
||||
|
||||
void init(string);
|
||||
void init(const string &);
|
||||
|
||||
void list_dir(const string &, list<string> &);
|
||||
unsigned int read_numdir(const string &, void (*)(ifstream &));
|
||||
void mkdir(string);
|
||||
void mkdir();
|
||||
void rm(string);
|
||||
void mkdir(const string &);
|
||||
void rm(const string &);
|
||||
|
||||
void save(string, void (*)(ofstream &, void *), DataState *, void *);
|
||||
void read(string, void (*)(ifstream &));
|
||||
|
|
|
@ -10,9 +10,9 @@ namespace libsaria
|
|||
{
|
||||
void init();
|
||||
|
||||
int get(string);
|
||||
void set(string, int);
|
||||
int init(string, int);
|
||||
int get(const string &);
|
||||
void set(const string &, int);
|
||||
int init(const string &, int);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ static string appdir;
|
|||
static mode_t dirmode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
static bool pipe_opened = false;
|
||||
|
||||
static void make_dir(string path)
|
||||
static void make_dir(const string &path)
|
||||
{
|
||||
println("Making directory: " + path);
|
||||
mkdir(path.c_str(), dirmode);
|
||||
|
@ -46,7 +46,7 @@ static bool compare_files(string &one, string &two)
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
bool exists(string filepath)
|
||||
bool exists(const string &filepath)
|
||||
{
|
||||
struct stat stat;
|
||||
return lstat(filepath.c_str(), &stat) == 0;
|
||||
|
@ -100,31 +100,26 @@ namespace libsaria
|
|||
return atoi(files.back().c_str()) + 1;
|
||||
}
|
||||
|
||||
void app::mkdir()
|
||||
{
|
||||
make_dir(appdir.c_str());
|
||||
}
|
||||
|
||||
void app::mkdir(string dir)
|
||||
void app::mkdir(const string &dir)
|
||||
{
|
||||
string d = appdir + "/" + dir;
|
||||
make_dir(d.c_str());
|
||||
}
|
||||
|
||||
void app::rm(string file)
|
||||
void app::rm(const string &file)
|
||||
{
|
||||
string f = appdir + "/" + file;
|
||||
remove(f.c_str());
|
||||
}
|
||||
|
||||
void app::init(string name)
|
||||
void app::init(const string &name)
|
||||
{
|
||||
string home = getenv("HOME");
|
||||
appdir = home + "/." + name;
|
||||
#ifdef DEBUG
|
||||
appdir += "-debug";
|
||||
#endif
|
||||
mkdir();
|
||||
make_dir(appdir.c_str());
|
||||
}
|
||||
|
||||
void app::save(string file, void (*func)(ofstream &, void *),
|
||||
|
|
|
@ -42,14 +42,14 @@ static void load(ifstream &stream)
|
|||
}
|
||||
}
|
||||
|
||||
static void set_preference(string key, int p)
|
||||
static void set_preference(const string &key, int p)
|
||||
{
|
||||
preferences[key] = p;
|
||||
state = DIRTY;
|
||||
libsaria::app::save("prefs", save, &state, NULL);
|
||||
}
|
||||
|
||||
static bool key_exists(string key)
|
||||
static bool key_exists(const string &key)
|
||||
{
|
||||
map<string, int>::iterator it;
|
||||
it = preferences.find(key);
|
||||
|
@ -64,7 +64,7 @@ namespace libsaria
|
|||
state = CLEAN;
|
||||
}
|
||||
|
||||
int prefs::get(string key)
|
||||
int prefs::get(const string &key)
|
||||
{
|
||||
map<string, int>::iterator it;
|
||||
it = preferences.find(key);
|
||||
|
@ -73,13 +73,13 @@ namespace libsaria
|
|||
return it->second;
|
||||
}
|
||||
|
||||
void prefs::set(string key, int value)
|
||||
void prefs::set(const string &key, int value)
|
||||
{
|
||||
if (get(key) != value)
|
||||
set_preference(key, value);
|
||||
}
|
||||
|
||||
int prefs::init(string key, int value)
|
||||
int prefs::init(const string &key, int value)
|
||||
{
|
||||
if (!key_exists(key)) {
|
||||
set_preference(key, value);
|
||||
|
|
Loading…
Reference in New Issue