Home | History | Annotate | Download | only in slang
      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 
     17 #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_  // NOLINT
     18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_
     19 
     20 #include "slang_rs_context.h"
     21 
     22 namespace slang {
     23 
     24 class RSExportable {
     25  public:
     26   enum Kind {
     27     EX_FUNC,
     28     EX_TYPE,
     29     EX_VAR,
     30     EX_FOREACH
     31   };
     32 
     33  private:
     34   RSContext *mContext;
     35 
     36   Kind mK;
     37 
     38  protected:
     39   RSExportable(RSContext *Context, RSExportable::Kind K)
     40       : mContext(Context),
     41         mK(K) {
     42     Context->newExportable(this);
     43     return;
     44   }
     45 
     46  public:
     47   inline Kind getKind() const { return mK; }
     48 
     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.
     52   // Return false if the exportable is kept or failed to keep.
     53   virtual bool keep();
     54   inline bool isKeep() const { return (mContext == NULL); }
     55 
     56   virtual bool equals(const RSExportable *E) const;
     57 
     58   inline RSContext *getRSContext() const { return mContext; }
     59 
     60   virtual ~RSExportable() { }
     61 };
     62 }
     63 
     64 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_  NOLINT
     65