123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- #ifndef MYSQLX_EXECUTABLE_H
- #define MYSQLX_EXECUTABLE_H
- #include "common.h"
- #include "result.h"
- #include "../common/op_if.h"
- namespace mysqlx {
- using std::ostream;
- template <class Res, class Op>
- class Executable
- {
- protected:
- using Impl = common::Executable_if;
- std::shared_ptr<Impl> m_impl;
- Executable() = default;
- void reset(Impl *impl)
- {
- m_impl.reset(impl);
- }
-
- void reset(const Executable &other)
- {
- m_impl.reset(other.m_impl->clone());
- }
- void reset(const Executable &&other)
- {
- m_impl = std::move(other.m_impl);
- }
- void check_if_valid()
- {
- if (!m_impl)
- throw Error("Attempt to use invalid operation");
- }
- Impl* get_impl()
- {
- check_if_valid();
- return m_impl.get();
- }
- public:
- Executable(const Executable &other)
- {
- operator=(other);
- }
- Executable(Executable &&other)
- {
- operator=(std::move(other));
- }
- virtual ~Executable() {}
- Executable& operator=(const Executable &other)
- {
- try {
- reset(other);
- return *this;
- }
- CATCH_AND_WRAP
- }
- Executable& operator=(Executable &&other)
- {
- try {
- reset(std::move(other));
- return *this;
- }
- CATCH_AND_WRAP
- }
-
- virtual Res execute()
- {
- try {
- check_if_valid();
-
- return m_impl->execute();
- }
- CATCH_AND_WRAP
- }
- struct Access;
- friend Access;
- };
- }
- #endif
|