1/* 2 * Copyright 2010-2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef BCC_SCRIPT_H 18#define BCC_SCRIPT_H 19 20namespace bcc { 21 22class Source; 23 24class Script { 25private: 26 // This is the source associated with this object and is going to be 27 // compiled. 28 Source *mSource; 29 30protected: 31 // This hook will be invoked after the script object is successfully reset. 32 virtual bool doReset() 33 { return true; } 34 35public: 36 Script(Source &pSource) : mSource(&pSource) { } 37 38 virtual ~Script() { } 39 40 // Reset this object with the new source supplied. Return false if this 41 // object remains unchanged after the call (e.g., the supplied source is 42 // the same with the one contain in this object.) If pPreserveCurrent is 43 // false, the current containing source will be destroyed after successfully 44 // reset. 45 bool reset(Source &pSource, bool pPreserveCurrent = false); 46 47 // Merge (or link) another source into the current source associated with 48 // this Script object. Return false on error. 49 // 50 // This is equivalent to the call to Script::merge(...) on mSource. 51 bool mergeSource(Source &pSource, bool pPreserveSource = false); 52 53 inline Source &getSource() 54 { return *mSource; } 55 inline const Source &getSource() const 56 { return *mSource; } 57}; 58 59} // end namespace bcc 60 61#endif // BCC_SCRIPT_H 62