[neurun] Introduce FunctionSequence (#4473)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Mon, 25 Feb 2019 09:21:41 +0000 (18:21 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 25 Feb 2019 09:21:41 +0000 (18:21 +0900)
Introduce `exec::FunctionSequence` class which is a linear composite of
`IFunction`.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/exec/FunctionSequence.cc [new file with mode: 0644]
runtimes/neurun/src/exec/FunctionSequence.h [new file with mode: 0644]

diff --git a/runtimes/neurun/src/exec/FunctionSequence.cc b/runtimes/neurun/src/exec/FunctionSequence.cc
new file mode 100644 (file)
index 0000000..293b98d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "FunctionSequence.h"
+
+namespace neurun
+{
+namespace exec
+{
+
+void FunctionSequence::run()
+{
+  for (const auto &function : _functions)
+  {
+    function->run();
+  }
+}
+
+void FunctionSequence::prepare()
+{
+  for (const auto &function : _functions)
+  {
+    function->prepare();
+  }
+}
+
+void FunctionSequence::append(std::unique_ptr<IFunction> &&function)
+{
+  _functions.push_back(std::move(function));
+}
+
+} // namespace exec
+} // namespace neurun
diff --git a/runtimes/neurun/src/exec/FunctionSequence.h b/runtimes/neurun/src/exec/FunctionSequence.h
new file mode 100644 (file)
index 0000000..464d105
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __NEURUN_EXEC_FUNCTION_SEQUENCE_H__
+#define __NEURUN_EXEC_FUNCTION_SEQUENCE_H__
+
+#include <memory>
+#include <vector>
+
+#include "exec/interface/IFunction.h"
+
+namespace neurun
+{
+namespace exec
+{
+
+class FunctionSequence : public IFunction
+{
+public:
+  virtual ~FunctionSequence() = default;
+
+  virtual void run() override;
+  virtual void prepare() override;
+
+  /**
+   * @brief Appends an IFunction object to the function sequence
+   *
+   * @param function IFunction object to be appended
+   */
+  void append(std::unique_ptr<IFunction> &&function);
+
+private:
+  std::vector<std::unique_ptr<IFunction>> _functions;
+};
+
+} // namespace exec
+} // namespace neurun
+
+#endif // __NEURUN_EXEC_FUNCTION_SEQUENCE_H__