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 __EntryPoint__H__ 17 #define __EntryPoint__H__ 18 19 #include <string> 20 #include <vector> 21 #include <stdio.h> 22 23 #include "Var.h" 24 25 //--------------------------------------------------- 26 27 typedef std::vector<Var> VarsArray; 28 29 class EntryPoint { 30 public: 31 EntryPoint(); 32 virtual ~EntryPoint(); 33 bool parse(unsigned int lc, const std::string & str); 34 void reset(); // reset the class to empty; 35 void print(FILE *fp = stdout, bool newline = true, 36 const std::string & name_suffix = std::string(""), 37 const std::string & name_prefix = std::string(""), 38 const std::string & ctx_param = std::string("")) const; name()39 const std::string & name() const { return m_name; } hostApiName()40 const std::string & hostApiName() const { 41 if (m_customHostApi.empty()) return m_name; 42 return m_customHostApi; 43 } vars()44 VarsArray & vars() { return m_vars; } vars()45 const VarsArray & vars() const { return m_vars; } retval()46 Var & retval() { return m_retval; } 47 Var * var(const std::string & name); 48 const Var * var(const std::string & name) const; 49 bool hasPointers(); unsupported()50 bool unsupported() const { return m_unsupported; } setUnsupported(bool state)51 void setUnsupported(bool state) { m_unsupported = state; } customDecoder()52 bool customDecoder() { return m_customDecoder; } setCustomDecoder(bool state)53 void setCustomDecoder(bool state) { m_customDecoder = state; } notApi()54 bool notApi() const { return m_notApi; } setNotApi(bool state)55 void setNotApi(bool state) { m_notApi = state; } flushOnEncode()56 bool flushOnEncode() const { return m_flushOnEncode; } setFlushOnEncode(bool state)57 void setFlushOnEncode(bool state) { m_flushOnEncode = state; } setCustomHostApi(const std::string & apiname)58 void setCustomHostApi(const std::string& apiname) { m_customHostApi = apiname; } 59 int validateVarAttr(const std::string& varname, size_t lc) const; 60 int setAttribute(const std::string &line, size_t lc); 61 62 private: 63 std::string m_name; 64 Var m_retval; 65 VarsArray m_vars; 66 bool m_unsupported; 67 bool m_customDecoder; 68 bool m_notApi; 69 bool m_flushOnEncode; 70 std::string m_customHostApi; 71 err(unsigned int lc,const char * msg)72 void err(unsigned int lc, const char *msg) { 73 fprintf(stderr, "line %d: %s\n", lc, msg); 74 } 75 }; 76 77 78 #endif 79