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 
20 namespace bcc {
21 
22 class Source;
23 
24 class Script {
25 private:
26   // This is the source associated with this object and is going to be
27   // compiled.
28   Source *mSource;
29 
30 protected:
31   // This hook will be invoked after the script object is successfully reset.
doReset()32   virtual bool doReset()
33   { return true; }
34 
35 public:
Script(Source & pSource)36   Script(Source &pSource) : mSource(&pSource) { }
37 
~Script()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);
52 
getSource()53   inline Source &getSource()
54   { return *mSource; }
getSource()55   inline const Source &getSource() const
56   { return *mSource; }
57 };
58 
59 } // end namespace bcc
60 
61 #endif  // BCC_SCRIPT_H
62