00001 // Filename: stringDecoder.h 00002 // Created by: drose (11Feb02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef STRINGDECODER_H 00016 #define STRINGDECODER_H 00017 00018 #include "dtoolbase.h" 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Class : StringDecoder 00022 // Description : The base class to a family of classes that decode 00023 // various kinds of encoded byte streams. Give it a 00024 // string, then ask it to pull the characters out one at 00025 // a time. This also serves as the plain old 00026 // byte-at-a-time decoder. 00027 //////////////////////////////////////////////////////////////////// 00028 class EXPCL_DTOOL StringDecoder { 00029 public: 00030 INLINE StringDecoder(const string &input); 00031 virtual ~StringDecoder(); 00032 00033 virtual int get_next_character(); 00034 INLINE bool is_eof(); 00035 00036 static void set_notify_ptr(ostream *ptr); 00037 static ostream *get_notify_ptr(); 00038 00039 protected: 00040 INLINE bool test_eof(); 00041 00042 string _input; 00043 size_t _p; 00044 bool _eof; 00045 static ostream *_notify_ptr; 00046 }; 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Class : StringUtf8Decoder 00050 // Description : This decoder extracts utf-8 sequences. 00051 //////////////////////////////////////////////////////////////////// 00052 class StringUtf8Decoder : public StringDecoder { 00053 public: 00054 INLINE StringUtf8Decoder(const string &input); 00055 00056 virtual int get_next_character(); 00057 }; 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Class : StringUnicodeDecoder 00061 // Description : This decoder extracts characters two at a time to get 00062 // a plain wide character sequence. 00063 //////////////////////////////////////////////////////////////////// 00064 class StringUnicodeDecoder : public StringDecoder { 00065 public: 00066 INLINE StringUnicodeDecoder(const string &input); 00067 00068 virtual int get_next_character(); 00069 }; 00070 00071 #include "stringDecoder.I" 00072 00073 #endif