The Pedigree Project  0.1
system/config/Config.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef CONFIG_H
21 #define CONFIG_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 #include "pedigree/kernel/utilities/String.h"
26 #include "sqlite3/sqlite3.h"
27 
28 extern sqlite3 *g_pSqlite;
29 
35 {
36  public:
37  class Result
38  {
39  public:
40  Result(char **ppResult, size_t rows, size_t cols, char *error, int ret);
41  ~Result();
42 
44  bool succeeded()
45  {
46  return m_Ret == 0;
47  }
49  char *errorMessage()
50  {
51  return m_pError;
52  }
53 
55  size_t rows()
56  {
57  return m_Rows;
58  }
60  size_t cols()
61  {
62  return m_Cols;
63  }
64 
66  String getColumnName(size_t n);
67 
69  String getStr(size_t row, size_t n);
71  size_t getNum(size_t row, size_t n);
73  bool getBool(size_t row, size_t n);
74 
76  String getStr(size_t row, const char *str);
78  size_t getNum(size_t row, const char *str);
80  bool getBool(size_t row, const char *str);
81 
82  private:
83  Result(const Result &);
84  Result &operator=(const Result &);
85 
86  size_t lookupCol(const char *str);
87 
88  char **m_ppResult;
89  size_t m_Rows, m_Cols;
90  char *m_pError;
91  int m_Ret;
92  };
93 
94  Config();
95  ~Config();
96 
97  static Config &instance()
98  {
99  return m_Instance;
100  }
101 
104  Result *query(const char *sql);
105 
106  private:
107  static Config m_Instance;
108 };
109 
110 #endif
Definition: String.h:49
Definition: Result.h:36