| $$ This is a pump file for generating file templates. Pump is a python | |
| $$ script that is part of the Google Test suite of utilities. Description | |
| $$ can be found here: | |
| $$ | |
| $$ http://code.google.com/p/googletest/wiki/PumpManual | |
| $$ | |
| $$ This should be no larger than MAX_ARITY in base/bind.h.pump. | |
| $var MAX_ARITY = 7 | |
| /* | |
| * Copyright 2015 Google Inc. 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 SCRIPT_CALLBACK_FUNCTION_H_ | |
| #define SCRIPT_CALLBACK_FUNCTION_H_ | |
| #include "base/callback.h" | |
| #include "base/callback_internal.h" | |
| // Abstract template interface that represents an IDL callback function | |
| // http://heycam.github.io/webidl/#idl-callback-functions | |
| // | |
| // The JavaScript implementation will instantiate a class that implements this | |
| // interface, and will execute JavaScript code when the Run(...) function is | |
| // executed. | |
| namespace cobalt { | |
| namespace script { | |
| template <typename R> | |
| struct CallbackResult { | |
| CallbackResult() : result(R()), exception(false) {} | |
| R result; | |
| bool exception; | |
| }; | |
| template <> | |
| struct CallbackResult<void> { | |
| CallbackResult() : exception(false) {} | |
| bool exception; | |
| }; | |
| // First, we forward declare the CallbackFunction class template. This informs | |
| // the compiler that the template only has 1 type parameter which is the | |
| // function signature that the CallbackFunction is representing. | |
| // | |
| // See base/callback.h.pump for further discussion on this pattern. | |
| template <typename Sig> | |
| class CallbackFunction; | |
| $range ARITY 0..MAX_ARITY | |
| $for ARITY [[ | |
| $range ARG 1..ARITY | |
| $if ARITY == 0 [[ | |
| template <typename R> | |
| class CallbackFunction<R(void)> { | |
| public: | |
| typedef R Signature(void); | |
| ]] $else [[ | |
| template <typename R, $for ARG , [[typename A$(ARG)]]> | |
| class CallbackFunction<R($for ARG , [[A$(ARG)]])> { | |
| public: | |
| typedef R Signature($for ARG , [[A$(ARG)]]); | |
| ]] | |
| typedef CallbackResult<R> ReturnValue; | |
| virtual CallbackResult<R> Run($for ARG ,[[ | |
| typename base::internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) | |
| const = 0; | |
| protected: | |
| virtual ~CallbackFunction() {} | |
| }; | |
| ]] | |
| } // namespace script | |
| } // namespace cobalt | |
| #endif // SCRIPT_CALLBACK_FUNCTION_H_ |