2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 // pointer data direction - from the client point of view.
26 typedef enum { POINTER_OUT = 0x1, POINTER_IN = 0x2, POINTER_INOUT = 0x3 } PointerDir;
31 m_pointerDir(POINTER_IN),
35 m_writeExpression(""),
36 m_paramCheckExpression("")
41 Var(const std::string & name,
42 const VarType * vartype,
43 const std::string & lenExpression,
45 const std::string &packExpression,
46 const std::string &writeExpression) :
48 m_type(const_cast<VarType *>(vartype)),
49 m_lenExpression(lenExpression),
53 m_packExpression(packExpression),
54 m_writeExpression(writeExpression),
55 m_paramCheckExpression("")
59 void init(const std::string name, const VarType * vartype,
60 std::string lenExpression,
62 std::string packExpression,
63 std::string writeExpression) {
66 m_lenExpression = lenExpression;
67 m_packExpression = packExpression;
68 m_writeExpression = writeExpression;
70 m_nullAllowed = false;
75 const std::string & name() const { return m_name; }
76 const VarType * type() const { return m_type; }
77 bool isPointer() const { return m_type->isPointer(); }
78 bool isVoid() const { return ((m_type->bytes() == 0) && (!m_type->isPointer())); }
79 const std::string & lenExpression() const { return m_lenExpression; }
80 const std::string & packExpression() const { return(m_packExpression); }
81 const std::string & writeExpression() const { return(m_writeExpression); }
82 const std::string & paramCheckExpression() const { return m_paramCheckExpression; }
83 void setLenExpression(const std::string & lenExpression) { m_lenExpression = lenExpression; }
84 void setPackExpression(const std::string & packExpression) { m_packExpression = packExpression; }
85 void setWriteExpression(const std::string & writeExpression) { m_writeExpression = writeExpression; }
86 void setParamCheckExpression(const std::string & paramCheckExpression) { m_paramCheckExpression = paramCheckExpression; }
87 void setPointerDir(PointerDir dir) { m_pointerDir = dir; }
88 PointerDir pointerDir() { return m_pointerDir; }
89 void setNullAllowed(bool state) { m_nullAllowed = state; }
90 void setIsLarge(bool state) { m_isLarge = state; }
91 bool nullAllowed() const { return m_nullAllowed; }
92 bool isLarge() const { return m_isLarge; }
93 void printType(FILE *fp) { fprintf(fp, "%s", m_type->name().c_str()); }
94 void printTypeName(FILE *fp) { printType(fp); fprintf(fp, " %s", m_name.c_str()); }
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;
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