1 /* 2 * Copyright (C) 2011 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 #ifndef __VAR__H__ 17 #define __VAR__H__ 18 19 #include "VarType.h" 20 #include <string> 21 #include <stdio.h> 22 23 class Var { 24 public: 25 // pointer data direction - from the client point of view. 26 typedef enum { POINTER_OUT = 0x1, POINTER_IN = 0x2, POINTER_INOUT = 0x3 } PointerDir; Var()27 Var() : 28 m_name(""), 29 m_type(NULL), 30 m_lenExpression(""), 31 m_pointerDir(POINTER_IN), 32 m_nullAllowed(false), 33 m_isLarge(false), 34 m_packExpression(""), 35 m_writeExpression(""), 36 m_paramCheckExpression("") 37 38 { 39 } 40 Var(const std::string & name,const VarType * vartype,const std::string & lenExpression,PointerDir dir,const std::string & packExpression,const std::string & writeExpression)41 Var(const std::string & name, 42 const VarType * vartype, 43 const std::string & lenExpression, 44 PointerDir dir, 45 const std::string &packExpression, 46 const std::string &writeExpression) : 47 m_name(name), 48 m_type(const_cast<VarType *>(vartype)), 49 m_lenExpression(lenExpression), 50 m_pointerDir(dir), 51 m_nullAllowed(false), 52 m_isLarge(false), 53 m_packExpression(packExpression), 54 m_writeExpression(writeExpression), 55 m_paramCheckExpression("") 56 { 57 } 58 init(const std::string name,const VarType * vartype,std::string lenExpression,PointerDir dir,std::string packExpression,std::string writeExpression)59 void init(const std::string name, const VarType * vartype, 60 std::string lenExpression, 61 PointerDir dir, 62 std::string packExpression, 63 std::string writeExpression) { 64 m_name = name; 65 m_type = vartype; 66 m_lenExpression = lenExpression; 67 m_packExpression = packExpression; 68 m_writeExpression = writeExpression; 69 m_pointerDir = dir; 70 m_nullAllowed = false; 71 m_isLarge = false; 72 73 } 74 name()75 const std::string & name() const { return m_name; } type()76 const VarType * type() const { return m_type; } isPointer()77 bool isPointer() const { return m_type->isPointer(); } isVoid()78 bool isVoid() const { return ((m_type->bytes() == 0) && (!m_type->isPointer())); } lenExpression()79 const std::string & lenExpression() const { return m_lenExpression; } packExpression()80 const std::string & packExpression() const { return(m_packExpression); } writeExpression()81 const std::string & writeExpression() const { return(m_writeExpression); } paramCheckExpression()82 const std::string & paramCheckExpression() const { return m_paramCheckExpression; } setLenExpression(const std::string & lenExpression)83 void setLenExpression(const std::string & lenExpression) { m_lenExpression = lenExpression; } setPackExpression(const std::string & packExpression)84 void setPackExpression(const std::string & packExpression) { m_packExpression = packExpression; } setWriteExpression(const std::string & writeExpression)85 void setWriteExpression(const std::string & writeExpression) { m_writeExpression = writeExpression; } setParamCheckExpression(const std::string & paramCheckExpression)86 void setParamCheckExpression(const std::string & paramCheckExpression) { m_paramCheckExpression = paramCheckExpression; } setPointerDir(PointerDir dir)87 void setPointerDir(PointerDir dir) { m_pointerDir = dir; } pointerDir()88 PointerDir pointerDir() { return m_pointerDir; } setNullAllowed(bool state)89 void setNullAllowed(bool state) { m_nullAllowed = state; } setIsLarge(bool state)90 void setIsLarge(bool state) { m_isLarge = state; } nullAllowed()91 bool nullAllowed() const { return m_nullAllowed; } isLarge()92 bool isLarge() const { return m_isLarge; } printType(FILE * fp)93 void printType(FILE *fp) { fprintf(fp, "%s", m_type->name().c_str()); } printTypeName(FILE * fp)94 void printTypeName(FILE *fp) { printType(fp); fprintf(fp, " %s", m_name.c_str()); } 95 96 private: 97 std::string m_name; 98 const VarType * m_type; 99 bool m_pointer; // is this variable a pointer; 100 std::string m_lenExpression; // an expression to calcualte a pointer data size 101 PointerDir m_pointerDir; 102 bool m_nullAllowed; 103 bool m_isLarge; 104 std::string m_packExpression; // an expression to pack data into the stream 105 std::string m_writeExpression; // an expression to write data into the stream 106 std::string m_paramCheckExpression; //an expression to check parameter value 107 108 }; 109 110 #endif 111