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 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_ |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 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, |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 29 | EX_VAR, |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 30 | EX_FOREACH, |
| 31 | EX_REDUCE |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
Zonr Chang | b257301 | 2010-10-07 19:35:21 +0800 | [diff] [blame] | 34 | private: |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 35 | RSContext *mContext; |
| 36 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 37 | Kind mK; |
| 38 | |
Zonr Chang | b257301 | 2010-10-07 19:35:21 +0800 | [diff] [blame] | 39 | protected: |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 40 | RSExportable(RSContext *Context, RSExportable::Kind K) |
| 41 | : mContext(Context), |
| 42 | mK(K) { |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 43 | Context->newExportable(this); |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 44 | } |
| 45 | |
Zonr Chang | b257301 | 2010-10-07 19:35:21 +0800 | [diff] [blame] | 46 | public: |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 47 | inline Kind getKind() const { return mK; } |
| 48 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 49 | // When keep() is invoked, mKeep will set to true and the associated RSContext |
| 50 | // won't free this RSExportable object in its destructor. The deallcation |
| 51 | // responsibility is then transferred to the object who invoked this function. |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame] | 52 | // Return false if the exportable is kept or failed to keep. |
| 53 | virtual bool keep(); |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 54 | inline bool isKeep() const { return (mContext == nullptr); } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 55 | |
| 56 | virtual bool equals(const RSExportable *E) const; |
| 57 | |
| 58 | inline RSContext *getRSContext() const { return mContext; } |
| 59 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 60 | virtual ~RSExportable() { } |
| 61 | }; |
Stephen Hines | e67239d | 2012-02-24 15:08:36 -0800 | [diff] [blame] | 62 | } // namespace slang |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 63 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 64 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_ NOLINT |