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; }
vars()40     VarsArray & vars() { return m_vars; }
retval()41     Var & retval() { return m_retval; }
42     Var * var(const std::string & name);
43     const Var * var(const std::string & name) const;
44     bool hasPointers();
unsupported()45     bool unsupported() const { return m_unsupported; }
setUnsupported(bool state)46     void setUnsupported(bool state) { m_unsupported = state; }
customDecoder()47     bool customDecoder() { return m_customDecoder; }
setCustomDecoder(bool state)48     void setCustomDecoder(bool state) { m_customDecoder = state; }
notApi()49     bool notApi() const { return m_notApi; }
setNotApi(bool state)50     void setNotApi(bool state) { m_notApi = state; }
flushOnEncode()51     bool flushOnEncode() const { return m_flushOnEncode; }
setFlushOnEncode(bool state)52     void setFlushOnEncode(bool state) { m_flushOnEncode = state; }
53     int validateVarAttr(const std::string& varname, size_t lc) const;
54     int setAttribute(const std::string &line, size_t lc);
55 
56 private:
57     std::string m_name;
58     Var m_retval;
59     VarsArray m_vars;
60     bool m_unsupported;
61     bool m_customDecoder;
62     bool m_notApi;
63     bool m_flushOnEncode;
64 
err(unsigned int lc,const char * msg)65     void err(unsigned int lc, const char *msg) {
66         fprintf(stderr, "line %d: %s\n", lc, msg);
67     }
68 };
69 
70 
71 #endif
72