// // Copyright (c) 2011 Alex Yatskov // // 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. // #pragma once namespace metacall { // // IFunctor // class IFunctor { public: virtual bool call(Deserializer* args, Serializer* ret) const = 0; }; // // Functor0p // template class Functor0p : public IFunctor { public: typedef R(*F)(); Functor0p(F function) : function_(function) { } bool call(Deserializer*, Serializer* ret) const { ret->write(function_()); return true; } private: F function_; }; template <> class Functor0p : public IFunctor { public: typedef void(*F)(); Functor0p(F function) : function_(function) { } bool call(Deserializer*, Serializer*) const { function_(); return true; } private: F function_; }; // // Functor1p // template class Functor1p : public IFunctor { public: typedef R (*F)(P1); Functor1p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; const bool success = args->read(&p1); if (success) { ret->write(function_(p1)); } return success; } private: F function_; }; template class Functor1p : public IFunctor { public: typedef void (*F)(P1); Functor1p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; const bool success = args->read(&p1); if (success) { function_(p1); } return success; } private: F function_; }; // // Functor2p // template class Functor2p : public IFunctor { public: typedef R (*F)(P1, P2); Functor2p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; const bool success = args->read(&p1) && args->read(&p2); if (success) { ret->write(function_(p1, p2)); } return success; } private: F function_; }; template class Functor2p : public IFunctor { public: typedef void (*F)(P1, P2); Functor2p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; const bool success = args->read(&p1) && args->read(&p2); if (success) { function_(p1, p2); } return success; } private: F function_; }; // // Functor3p // template class Functor3p : public IFunctor { public: typedef R (*F)(P1, P2, P3); Functor3p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3); if (success) { ret->write(function_(p1, p2, p3)); } return success; } private: F function_; }; template class Functor3p : public IFunctor { public: typedef void (*F)(P1, P2, P3); Functor3p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3); if (success) { function_(p1, p2, p3); } return success; } private: F function_; }; // // Functor4p // template class Functor4p : public IFunctor { public: typedef R (*F)(P1, P2, P3, P4); Functor4p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4); if (success) { ret->write(function_(p1, p2, p3, p4)); } return success; } private: F function_; }; template class Functor4p : public IFunctor { public: typedef void (*F)(P1, P2, P3, P4); Functor4p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4); if (success) { function_(p1, p2, p3, p4); } return success; } private: F function_; }; // // Functor5p // template class Functor5p : public IFunctor { public: typedef R (*F)(P1, P2, P3, P4, P5); Functor5p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5); if (success) { ret->write(function_(p1, p2, p3, p4, p5)); } return success; } private: F function_; }; template class Functor5p : public IFunctor { public: typedef void (*F)(P1, P2, P3, P4, P5); Functor5p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5); if (success) { function_(p1, p2, p3, p4, p5); } return success; } private: F function_; }; // // Functor6p // template class Functor6p : public IFunctor { public: typedef R (*F)(P1, P2, P3, P4, P5, P6); Functor6p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6); if (success) { ret->write(function_(p1, p2, p3, p4, p5, p6)); } return success; } private: F function_; }; template class Functor6p : public IFunctor { public: typedef void (*F)(P1, P2, P3, P4, P5, P6); Functor6p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6); if (success) { function_(p1, p2, p3, p4, p5, p6); } return success; } private: F function_; }; // // Functor7p // template class Functor7p : public IFunctor { public: typedef R (*F)(P1, P2, P3, P4, P5, P6, P7); Functor7p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; typename StripConstRef::Type p7; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6) && args->read(&p7); if (success) { ret->write(function_(p1, p2, p3, p4, p5, p6, p7)); } return success; } private: F function_; }; template class Functor7p : public IFunctor { public: typedef void (*F)(P1, P2, P3, P4, P5, P6, P7); Functor7p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; typename StripConstRef::Type p7; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6) && args->read(&p7); if (success) { function_(p1, p2, p3, p4, p5, p6, p7); } return success; } private: F function_; }; // // Functor8p // template class Functor8p : public IFunctor { public: typedef R (*F)(P1, P2, P3, P4, P5, P6, P7, P8); Functor8p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; typename StripConstRef::Type p7; typename StripConstRef::Type p8; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6) && args->read(&p7) && args->read(&p8); if (success) { ret->write(function_(p1, p2, p3, p4, p5, p6, p7, p8)); } return success; } private: F function_; }; template class Functor8p : public IFunctor { public: typedef void (*F)(P1, P2, P3, P4, P5, P6, P7, P8); Functor8p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; typename StripConstRef::Type p7; typename StripConstRef::Type p8; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6) && args->read(&p7) && args->read(&p8); if (success) { function_(p1, p2, p3, p4, p5, p6, p7, p8); } return success; } private: F function_; }; // // Functor9p // template class Functor9p : public IFunctor { public: typedef R (*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9); Functor9p(F function) : function_(function) { } bool call(Deserializer* args, Serializer* ret) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; typename StripConstRef::Type p7; typename StripConstRef::Type p8; typename StripConstRef::Type p9; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6) && args->read(&p7) && args->read(&p8) && args->read(&p9); if (success) { ret->write(function_(p1, p2, p3, p4, p5, p6, p7, p8, p9)); } return success; } private: F function_; }; template class Functor9p : public IFunctor { public: typedef void (*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9); Functor9p(F function) : function_(function) { } bool call(Deserializer* args, Serializer*) const { typename StripConstRef::Type p1; typename StripConstRef::Type p2; typename StripConstRef::Type p3; typename StripConstRef::Type p4; typename StripConstRef::Type p5; typename StripConstRef::Type p6; typename StripConstRef::Type p7; typename StripConstRef::Type p8; typename StripConstRef::Type p9; const bool success = args->read(&p1) && args->read(&p2) && args->read(&p3) && args->read(&p4) && args->read(&p5) && args->read(&p6) && args->read(&p7) && args->read(&p8) && args->read(&p9); if (success) { function_(p1, p2, p3, p4, p5, p6, p7, p8, p9); } return success; } private: F function_; }; }