/*
* freescope - Free source browser
* Copyright (C) 2001 Olivier Deme
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
/*
* FILE: dbuser.h
*
* DESCRIPTION: This file defines the class DbUser that interacts with a Dal
* (Database Abstraction Layer) object.
* It is able to call the parser passing pointers to function
* for database access.
* It encodes en decodes records coming from and going to the
* database.
* This class is a singleton.
*/
#ifndef _DBUSER_H_
#define _DBUSER_H_
/************/
/* INCLUDES */
/************/
#include <string>
#include <list>
#include <set>
#include "defs.h"
#include "parser.h"
#include "dbinf.h"
/*********************/
/* NAMESPACE SYMBOLS */
/*********************/
using std::string;
using std::list;
using std::set;
/**********/
/* MACROS */
/**********/
#define DBUSER (DbUser::instance())
/**************************/
/* CLASS PRE-DECLARATIONS */
/**************************/
class ifstream;
/*********************/
/* CLASS DEFINITIONS */
/*********************/
class DbUser
{
// TYPE DEFINITIONS
public:
typedef enum
{
UI_NONE,
UI_CLI,
UI_TK,
UI_CURSES
} ui_type_t;
typedef enum
{
QUERY_NOT_SUPPORTED = 0,
QUERY_SYMBOL,
QUERY_DEFINITION,
QUERY_CALLED,
QUERY_CALL,
QUERY_TEXT,
QUERY_REGEXP,
QUERY_FILE,
QUERY_INCLUDE
} query_type_t;
// CONSTRUCTORS
public:
DbUser ();
virtual ~DbUser ();
// METHODS
public:
virtual void display_result () {};
virtual void do_loop () {};
static DbUser* create (const ui_type_t type = UI_CURSES);
static DbUser* instance ();
static void store_file (char* header, size_t length);
void do_query (const query_type_t type,
string& symbol);
protected:
void update ();
string read_line (const string& filename,
const line_nbr_t lineno);
virtual void do_init () {};
virtual void set_status (string message, bool center = true) {};
virtual void terminate (const string& reason) { exit(-1); };
virtual string next_completion (const string& stub, int& index, int& total);
virtual string prev_completion (const string& stub, int& index, int& total);
private:
bool update (string& filename);
void RemoveDuplicates ();
void find_sys_headers (string&, string&);
void parse_headers ();
void find_text (string& text);
void find_regexp (const string& regexp);
void find_file (string& file);
// ATTRIBUTES
private:
string m_file;
set<string> m_headers;
set<string> m_headers_found;
set<string> m_added_files;
bool m_do_headers;
protected:
static DbUser* m_instance;
ifstream* m_resFile;
DbInf* m_dbinf;
list<match_t> m_result;
list<match_t>::iterator m_curr_result;
};
class DbUser_Exception : public exception
{
// FRIENDS
friend class CursUI;
friend class Cli;
// CONSTRUCTORS
private:
DbUser_Exception () {};
DbUser_Exception (const string& description) {m_description = description;};
// METHODS:
public:
string what () { return m_description; };
// ATTRIBUTES
private:
string m_description;
};
#endif // _DBUSER_H_
syntax highlighted by Code2HTML, v. 0.9.1