Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010, 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 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 17 | #ifndef _SLANG_COMPILER_RS_EXPORTABLE_HPP |
| 18 | #define _SLANG_COMPILER_RS_EXPORTABLE_HPP |
| 19 | |
| 20 | #include "slang_rs_context.h" |
| 21 | |
| 22 | namespace slang { |
| 23 | |
| 24 | class RSExportable { |
Zonr Chang | b257301 | 2010-10-07 19:35:21 +0800 | [diff] [blame] | 25 | public: |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 26 | enum Kind { |
| 27 | EX_FUNC, |
| 28 | EX_TYPE, |
| 29 | EX_VAR |
| 30 | }; |
| 31 | |
Zonr Chang | b257301 | 2010-10-07 19:35:21 +0800 | [diff] [blame] | 32 | private: |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 33 | RSContext *mContext; |
| 34 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 35 | Kind mK; |
| 36 | |
Zonr Chang | b257301 | 2010-10-07 19:35:21 +0800 | [diff] [blame] | 37 | protected: |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 38 | RSExportable(RSContext *Context, RSExportable::Kind K) |
| 39 | : mContext(Context), |
| 40 | mK(K) { |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 41 | Context->newExportable(this); |
| 42 | return; |
| 43 | } |
| 44 | |
Zonr Chang | b257301 | 2010-10-07 19:35:21 +0800 | [diff] [blame] | 45 | public: |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 46 | inline Kind getKind() const { return mK; } |
| 47 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 48 | // When keep() is invoked, mKeep will set to true and the associated RSContext |
| 49 | // won't free this RSExportable object in its destructor. The deallcation |
| 50 | // responsibility is then transferred to the object who invoked this function. |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame^] | 51 | // Return false if the exportable is kept or failed to keep. |
| 52 | virtual bool keep(); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 53 | inline bool isKeep() const { return (mContext == NULL); } |
| 54 | |
| 55 | virtual bool equals(const RSExportable *E) const; |
| 56 | |
| 57 | inline RSContext *getRSContext() const { return mContext; } |
| 58 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 59 | virtual ~RSExportable() { } |
| 60 | }; |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | #endif // _SLANG_COMPILER_RS_EXPORTABLE_HPP |