//////////////////////////////////////////////////////////////////////////////// // // Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // // http://www.opensource.org/licenses/mit-license.php // //////////////////////////////////////////////////////////////////////////////// #ifndef INCLUDED_TDB2 #define INCLUDED_TDB2 #include #include #include #include #include #include #include // TF2 Class represents a single file in the task database. class TF2 { public: TF2 (); ~TF2 (); void target (const std::string&); const std::vector & get_tasks (); const std::vector & get_lines (); bool get (int, Task&); bool get (const std::string&, Task&); bool has (const std::string&); void add_task (Task&); bool modify_task (const Task&); void add_line (const std::string&); void clear_tasks (); void clear_lines (); void commit (); void load_tasks (); void load_lines (); // ID <--> UUID mapping. std::string uuid (int); int id (const std::string&); void has_ids (); void auto_dep_scan (); void clear (); const std::string dump (); private: void dependency_scan (); public: bool _read_only; bool _dirty; bool _loaded_tasks; bool _loaded_lines; bool _has_ids; bool _auto_dep_scan; std::vector _tasks; std::vector _added_tasks; std::vector _modified_tasks; std::vector _lines; std::vector _added_lines; File _file; private: std::map _I2U; // ID -> UUID map std::map _U2I; // UUID -> ID map }; // TDB2 Class represents all the files in the task database. class TDB2 { public: TDB2 (); ~TDB2 (); void set_location (const std::string&); void add (Task&, bool add_to_backlog = true); void modify (Task&, bool add_to_backlog = true); void commit (); void get_changes (std::vector &); void revert (); int gc (); int next_id (); // Generalized task accessors. const std::vector all_tasks (); bool get (int, Task&); bool get (const std::string&, Task&); bool has (const std::string&); const std::vector siblings (Task&); const std::vector children (Task&); // ID <--> UUID mapping. std::string uuid (int); int id (const std::string&); // Read-only mode. bool read_only (); void clear (); void dump (); private: void gather_changes (); void update (const std::string&, Task&, const bool, const bool addition = false); bool verifyUniqueUUID (const std::string&); void show_diff (const std::string&, const std::string&, const std::string&); void revert_undo (std::vector &, std::string&, std::string&, std::string&, std::string&); void revert_pending (std::vector &, const std::string&, const std::string&, const std::string&); void revert_completed (std::vector &, std::vector &, const std::string&, const std::string&, const std::string&); void revert_backlog (std::vector &, const std::string&, const std::string&, const std::string&); public: TF2 pending; TF2 completed; TF2 undo; TF2 backlog; private: std::string _location; int _id; std::vector _changes; }; #endif ////////////////////////////////////////////////////////////////////////////////