presageCallback.h

Go to the documentation of this file.
00001 
00002 /******************************************************
00003  *  Presage, an extensible predictive text entry system
00004  *  ---------------------------------------------------
00005  *
00006  *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License along
00019     with this program; if not, write to the Free Software Foundation, Inc.,
00020     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00021                                                                              *
00022                                                                 **********(*)*/
00023 
00024 
00025 #ifndef PRESAGE_CALLBACK
00026 #define PRESAGE_CALLBACK
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032     typedef const char* (*_presage_callback_get_past_stream)   (void*);
00033     typedef const char* (*_presage_callback_get_future_stream) (void*);
00034 
00035 #ifdef __cplusplus
00036 }
00037 #endif
00038 
00039 
00040 #ifdef __cplusplus
00041 #ifndef _MSC_VER
00042 
00043 #include <string>
00044 #include <sstream>
00045 
00066 class PresageCallback {
00067 public:
00068     virtual ~PresageCallback() { };
00069 
00070     virtual std::string get_past_stream() const = 0;
00071     virtual std::string get_future_stream() const = 0;
00072 
00073 protected:
00074     PresageCallback() { };
00075 
00076 };
00077 
00078 
00094 class LegacyPresageCallback : public PresageCallback {
00095 public:
00096     LegacyPresageCallback() { }
00097     ~LegacyPresageCallback() { }
00098     
00099     std::string get_past_stream() const { return m_stream; }
00100     std::string get_future_stream() const { return m_empty; }
00101 
00102     void update(std::string str) { for (size_t sz = 0; sz < str.size(); sz++) { update(str[sz]); } }
00103 
00104 private:
00105     void update(int character) { 
00106         if (character == '\b'
00107             && ! m_stream.empty()) {
00108             m_stream.erase(m_stream.end() - 1);
00109         } else {
00110             m_stream.push_back(character);
00111         }
00112     }
00113 
00114     std::string m_stream;
00115     const std::string m_empty;
00116 };
00117 
00118 #endif /* _MSC_VER */
00119 #endif /* _cplusplus */
00120 
00121 #endif /* PRESAGE_CALLBACK */

Generated on 9 Feb 2015 for presage by  doxygen 1.6.1