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 __VARTYPE__H__ 17 #define __VARTYPE__H__ 18 19 #include <string> 20 21 class VarConverter { 22 public: 23 VarConverter(size_t bytes) : m_bytes(bytes) {} 24 size_t bytes() const { return m_bytes; } 25 private: 26 size_t m_bytes; 27 }; 28 29 class Var8 : public VarConverter { 30 public: 31 Var8() : VarConverter(1) {} 32 }; 33 34 class Var16 : public VarConverter { 35 public: 36 Var16() : VarConverter(2) {} 37 }; 38 39 class Var32 : public VarConverter { 40 public: 41 Var32() : VarConverter(4) {} 42 }; 43 44 class Var0 : public VarConverter { 45 public: 46 Var0() : VarConverter(0) {} 47 }; 48 49 50 class VarType { 51 public: 52 VarType() : 53 m_id(0), m_name("default_constructed"), m_converter(NULL), m_printFomrat("0x%x"), m_isPointer(false) 54 { 55 } 56 57 VarType(size_t id, const std::string & name, const VarConverter * converter, const std::string & printFormat , const bool isPointer) : 58 m_id(id), m_name(name), m_converter(const_cast<VarConverter *>(converter)), m_printFomrat(printFormat), m_isPointer(isPointer) 59 { 60 } 61 62 ~VarType() 63 { 64 } 65 const std::string & name() const { return m_name; } 66 const std::string & printFormat() const { return m_printFomrat; } 67 size_t bytes() const { return m_converter->bytes(); } 68 bool isPointer() const { return m_isPointer; } 69 size_t id() const { return m_id; } 70 private: 71 size_t m_id; 72 std::string m_name; 73 VarConverter * m_converter; 74 std::string m_printFomrat; 75 bool m_isPointer; 76 }; 77 78 #endif 79