Script.h revision 80232dd16c0affb2afae01cde6c94abf23ac1ba8
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 succssfully reset 32 // itself. 33 virtual bool doReset() 34 { return true; } 35 36public: 37 Script(Source &pSource) : mSource(&pSource) { } 38 39 virtual ~Script() { } 40 41 // Reset this object with the new source supplied. Return false if this 42 // object remains unchanged after the call (e.g., the supplied source is 43 // the same with the one contain in this object.) If pPreserveCurrent is 44 // false, the current containing source will be destroyed after successfully 45 // reset. 46 bool reset(Source &pSource, bool pPreserveCurrent = false); 47 48 // Merge (or link) another source into the current source associated with 49 // this Script object. Return false on error. 50 // 51 // This is equivalent to the call to Script::merge(...) on mSource. 52 bool mergeSource(Source &pSource, bool pPreserveSource = false); 53 54 inline Source &getSource() 55 { return *mSource; } 56 inline const Source &getSource() const 57 { return *mSource; } 58}; 59 60} // end namespace bcc 61 62#endif // BCC_SCRIPT_H 63