From 2fdc3eba4a87a61ba81ad2504a7eb85d7e71391c Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Wed, 18 Jul 2018 21:04:20 +0200 Subject: [PATCH] #9 TI-1: Add data types Transaction and UndoAction --- src/CMakeLists.txt | 2 ++ src/Transaction.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/Transaction.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/UndoAction.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/UndoAction.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 src/Transaction.cpp create mode 100644 src/Transaction.h create mode 100644 src/UndoAction.cpp create mode 100644 src/UndoAction.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 087c006a..ecfbf14a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,8 @@ set (timew_SRCS CLI.cpp CLI.h Interval.cpp Interval.h Range.cpp Range.h Rules.cpp Rules.h + Transaction.cpp Transaction.h + UndoAction.cpp UndoAction.h data.cpp dom.cpp init.cpp diff --git a/src/Transaction.cpp b/src/Transaction.cpp new file mode 100644 index 00000000..93fc1635 --- /dev/null +++ b/src/Transaction.cpp @@ -0,0 +1,36 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2018, Thomas Lauf, 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. +// +// https://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include + +void Transaction::addUndoAction ( + const std::string& type, + const std::string& before, + const std::string& after) +{ + _actions.emplace_back (type, before, after); +} diff --git a/src/Transaction.h b/src/Transaction.h new file mode 100644 index 00000000..e58c851d --- /dev/null +++ b/src/Transaction.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2018, Thomas Lauf, 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. +// +// https://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_TRANSACTION +#define INCLUDED_TRANSACTION + +#include +#include + +class Transaction +{ +public: + void addUndoAction(const std::string&, const std::string&, const std::string&); + +private: + std::vector _actions {}; +}; + +#endif diff --git a/src/UndoAction.cpp b/src/UndoAction.cpp new file mode 100644 index 00000000..4b989f06 --- /dev/null +++ b/src/UndoAction.cpp @@ -0,0 +1,37 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2018, Thomas Lauf, 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. +// +// https://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include + +UndoAction::UndoAction ( + const std::string& type, + const std::string& before, + const std::string& after) +{ + _type = type; + _before = before; + _after = after; +} diff --git a/src/UndoAction.h b/src/UndoAction.h new file mode 100644 index 00000000..3236505f --- /dev/null +++ b/src/UndoAction.h @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2018, Thomas Lauf, 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. +// +// https://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_UNDOACTION +#define INCLUDED_UNDOACTION + +#include + +class UndoAction +{ +public: + UndoAction(const std::string&, const std::string&, const std::string&); + +private: + std::string _type; + std::string _before; + std::string _after; +}; + +#endif