mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Path integration
- Implemented Path::operator (std::string) const, to provide an automatic cast to std::string for any Path, File or Directory. - Made use of new cast in various code. - Changed use of spaces in atoi () calls. - Switched from std::string::data () to std::string::c_str () calls.
This commit is contained in:
parent
a6875ced6e
commit
e53ba8110b
9 changed files with 35 additions and 18 deletions
|
@ -321,7 +321,7 @@ void Config::parse (const std::string& input, int nest /* = 1 */)
|
|||
if (included.is_absolute ())
|
||||
{
|
||||
if (included.readable ())
|
||||
this->load (included.data, nest + 1);
|
||||
this->load (included, nest + 1);
|
||||
else
|
||||
throw std::string ("Could not read include file '") + included.data + "'";
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ void Context::initialize ()
|
|||
// init TDB.
|
||||
tdb.clear ();
|
||||
std::vector <std::string> all;
|
||||
split (all, location.data, ',');
|
||||
split (all, location, ',');
|
||||
foreach (path, all)
|
||||
tdb.location (*path);
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ void Context::loadCorrectConfigFile ()
|
|||
file_override = *arg;
|
||||
rc = File (arg->substr (3));
|
||||
|
||||
home = rc.data;
|
||||
home = rc;
|
||||
std::string::size_type last_slash = rc.data.rfind ("/");
|
||||
if (last_slash != std::string::npos)
|
||||
home = rc.data.substr (0, last_slash);
|
||||
|
@ -388,7 +388,7 @@ void Context::loadCorrectConfigFile ()
|
|||
// Load rc file.
|
||||
config.clear (); // Dump current values.
|
||||
config.setDefaults (); // Add in the custom reports.
|
||||
config.load (rc.data); // Load new file.
|
||||
config.load (rc); // Load new file.
|
||||
|
||||
if (config.get ("data.location") != "")
|
||||
data = Directory (config.get ("data.location"));
|
||||
|
@ -417,19 +417,19 @@ void Context::loadCorrectConfigFile ()
|
|||
+ rc.data
|
||||
+ " created, so task can proceed?"))
|
||||
{
|
||||
config.createDefaultRC (rc.data, data.data);
|
||||
config.createDefaultRC (rc, data);
|
||||
}
|
||||
else
|
||||
throw std::string ("Cannot proceed without rc file.");
|
||||
}
|
||||
|
||||
// Create data location, if necessary.
|
||||
config.createDefaultData (data.data);
|
||||
config.createDefaultData (data);
|
||||
|
||||
// Load rc file.
|
||||
config.clear (); // Dump current values.
|
||||
config.setDefaults (); // Add in the custom reports.
|
||||
config.load (rc.data); // Load new file.
|
||||
config.load (rc); // Load new file.
|
||||
|
||||
// Apply overrides of type: "rc.name:value", or "rc.name=value".
|
||||
std::vector <std::string> filtered;
|
||||
|
|
|
@ -65,6 +65,12 @@ Path& Path::operator= (const Path& other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Path::operator std::string () const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Path::name () const
|
||||
{
|
||||
|
|
|
@ -39,6 +39,8 @@ public:
|
|||
virtual ~Path ();
|
||||
|
||||
Path& operator= (const Path&);
|
||||
operator std::string () const;
|
||||
|
||||
std::string name () const;
|
||||
std::string parent () const;
|
||||
std::string extension () const;
|
||||
|
|
|
@ -114,7 +114,7 @@ void TDB::location (const std::string& path)
|
|||
path +
|
||||
"' does not exist, or is not readable and writable.";
|
||||
|
||||
mLocations.push_back (Location (d.data));
|
||||
mLocations.push_back (Location (d));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -1535,7 +1535,7 @@ int handleReportCalendar (std::string &outs)
|
|||
// task cal 2010
|
||||
monthsToDisplay = 12;
|
||||
mFrom = 1;
|
||||
yFrom = atoi( context.args[1].data());
|
||||
yFrom = atoi (context.args[1].c_str ());
|
||||
}
|
||||
}
|
||||
else if (numberOfArgs == 3) {
|
||||
|
@ -1547,15 +1547,15 @@ int handleReportCalendar (std::string &outs)
|
|||
else {
|
||||
// task cal 8 2010
|
||||
monthsToDisplay = monthsPerLine;
|
||||
mFrom = atoi( context.args[1].data());
|
||||
yFrom = atoi( context.args[2].data());
|
||||
mFrom = atoi (context.args[1].c_str ());
|
||||
yFrom = atoi (context.args[2].c_str ());
|
||||
}
|
||||
}
|
||||
else if (numberOfArgs == 4) {
|
||||
// task cal 8 2010 y
|
||||
monthsToDisplay = 12;
|
||||
mFrom = atoi( context.args[1].data());
|
||||
yFrom = atoi( context.args[2].data());
|
||||
mFrom = atoi (context.args[1].c_str ());
|
||||
yFrom = atoi (context.args[2].c_str ());
|
||||
}
|
||||
|
||||
int countDueDates = 0;
|
||||
|
@ -1728,7 +1728,7 @@ int handleReportStats (std::string &outs)
|
|||
dataSize += undo.size ();
|
||||
|
||||
std::vector <std::string> undoTxns;
|
||||
slurp (undo.data, undoTxns, false);
|
||||
slurp (undo, undoTxns, false);
|
||||
int undoCount = 0;
|
||||
foreach (tx, undoTxns)
|
||||
if (tx->substr (0, 3) == "---")
|
||||
|
|
|
@ -33,7 +33,7 @@ Context context;
|
|||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (20);
|
||||
UnitTest t (21);
|
||||
|
||||
// Directory (const File&);
|
||||
// Directory (const Path&);
|
||||
|
@ -55,6 +55,9 @@ int main (int argc, char** argv)
|
|||
Directory d5 = d4;
|
||||
t.is (d5.data, "/tmp/test_directory", "Directory::operator=");
|
||||
|
||||
// operator (std::string) const;
|
||||
t.is ((std::string) d3, "/tmp", "Directory::operator (std::string) const");
|
||||
|
||||
// virtual bool create ();
|
||||
t.ok (d5.create (), "Directory::create /tmp/test_directory");
|
||||
t.ok (d5.exists (), "Directory::exists /tmp/test_directory");
|
||||
|
|
|
@ -33,7 +33,7 @@ Context context;
|
|||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (5);
|
||||
UnitTest t (6);
|
||||
|
||||
File::write ("/tmp/file.t.txt", "This is a test\n");
|
||||
File f6 ("/tmp/file.t.txt");
|
||||
|
@ -41,6 +41,9 @@ int main (int argc, char** argv)
|
|||
t.ok (f6.mode () & S_IRUSR, "File::mode /tmp/file.t.txt good");
|
||||
t.ok (File::remove ("/tmp/file.t.txt"), "File::remove /tmp/file.t.txt good");
|
||||
|
||||
// operator (std::string) const;
|
||||
t.is ((std::string) f6, "/tmp/file.t.txt", "File::operator (std::string) const");
|
||||
|
||||
t.ok (File::create ("/tmp/file.t.create"), "File::create /tmp/file.t.create good");
|
||||
t.ok (File::remove ("/tmp/file.t.create"), "File::remove /tmp/file.t.create good");
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// Copyright 2006 - 2010, Paul Beckingham.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
|
@ -33,7 +33,7 @@ Context context;
|
|||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (31);
|
||||
UnitTest t (32);
|
||||
|
||||
// Path ();
|
||||
Path p0;
|
||||
|
@ -54,6 +54,9 @@ int main (int argc, char** argv)
|
|||
Path p3_copy (p3);
|
||||
t.is (p3.data, p3_copy.data, "Path::Path (Path&)");
|
||||
|
||||
// operator (std::string) const;
|
||||
t.is ((std::string) p3, "/tmp", "Path::operator (std::string) const");
|
||||
|
||||
// std::string name () const;
|
||||
Path p4 ("/a/b/c/file.ext");
|
||||
t.is (p4.name (), "file.ext", "/a/b/c/file.ext name is file.ext");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue