00001 #include "config.h"
00002
00003 #include <iostream>
00004 #include <fstream>
00005 #include <string>
00006
00007 #include "debug.h"
00008 #include "d_debug.h"
00009
00010 #ifdef DEBUG
00011
00012
00013 const size_t d_debug::m_buffer_size = 1024;
00014
00015 d_debug::d_debug()
00016 {
00017 size_t c;
00018
00019 m_ok = false;
00020
00021 m_buffer = new char[m_buffer_size];
00022 if (m_buffer == 0)
00023 return;
00024
00025 for (c = 0; c < m_buffer_size; ++c)
00026 m_buffer[c] = 0;
00027
00028 m_ok = true;
00029 }
00030
00031 d_debug::~d_debug()
00032 {
00033 if (!m_ok)
00034 return;
00035 delete[] m_buffer;
00036 }
00037
00038 bool d_debug::open(const std::string& a_filename)
00039 {
00040 m_in.open(a_filename.c_str());
00041 if (!m_in.is_open())
00042 return(false);
00043 return(true);
00044 }
00045
00046 bool d_debug::close(void)
00047 {
00048 if (m_in.is_open())
00049 m_in.close();
00050 return(true);
00051 }
00052
00053 bool d_debug::is_open(void)
00054 {
00055 return(m_in.is_open());
00056 }
00057
00058 bool d_debug::get_line()
00059 {
00060 if (!m_ok)
00061 return(false);
00062 mf_clear_buffer();
00063 if (!m_in.getline(m_buffer,m_buffer_size))
00064 return(false);
00065 try {
00066 m_str = std::string(m_buffer);
00067 }
00068 catch(...) {
00069 std::cerr
00070 << "*** ERROR: d_debug::getline() - Out of memory?"
00071 << std::endl;
00072 return(false);
00073 }
00074 return(true);
00075 }
00076
00077 bool d_debug::str_equal(const std::string& a_str)
00078 {
00079 return(m_str == a_str);
00080 }
00081
00082 bool d_debug::str_begin(const std::string& a_str)
00083 {
00084 if (m_str.substr(0,a_str.size()) == a_str)
00085 return(true);
00086 return(false);
00087 }
00088
00089 bool d_debug::str_end(const std::string& a_str)
00090 {
00091 if (m_str.substr(m_str.size()-a_str.size()) == a_str)
00092 return(true);
00093 return(false);
00094 }
00095
00096 bool d_debug::str_between(
00097 const std::string& a_str,
00098 std::string::size_type a_begin,
00099 std::string::size_type a_end
00100 )
00101 {
00102 std::string::size_type idx;
00103
00104 idx = m_str.find(a_str,a_begin);
00105 if ((idx != std::string::npos) && (idx+a_str.size() <= a_end))
00106 return(true);
00107 return(false);
00108 }
00109
00110 bool d_debug::str_wrap(const std::string& a_begin, const std::string& a_end)
00111 {
00112 return(str_begin(a_begin) && str_end(a_end));
00113 }
00114
00115 bool d_debug::str_sandwich(
00116 const std::string& a_begin,
00117 const std::string& a_middle,
00118 const std::string& a_end
00119 )
00120 {
00121 return(
00122 str_begin(a_begin)
00123 && str_between(a_middle,a_begin.size(),m_str.size()-a_end.size())
00124 && str_end(a_end)
00125 );
00126 }
00127
00128 void d_debug::mf_clear_buffer(void)
00129 {
00130 size_t c;
00131
00132 for (c = 0; c < m_buffer_size; ++c)
00133 m_buffer[c] = 0;
00134 }
00135
00136
00137
00138 d_debug ddbg;
00139
00140
00141 #endif