# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlCore/TextStream.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef TextStream_INCLUDE_ONCE
    00033 #define TextStream_INCLUDE_ONCE
    00034
    00035 #include <vlCore/BufferedStream.hpp>
    00036
    00037 namespace vl
    00038 {
    00039 //-----------------------------------------------------------------------------
    00040 // TextStream
    00041 //-----------------------------------------------------------------------------
    00045   class VLCORE_EXPORT TextStream: public BufferedStream<unsigned char, 128*1024>
    00046   {
    00047   public:
    00048     virtual const char* className() { return "vl::TextStream"; }
    00049     TextStream(VirtualFile* file=NULL)
    00050     {
    00051       setInputFile(file);
    00052     }
    00053     ~TextStream()
    00054     {
    00055       if(inputFile())
    00056         inputFile()->close();
    00057     }
    00058
    00059     void ungetLine(const std::string& utf8)
    00060     {
    00061       ungetToken('\n');
    00062       for(size_t i=utf8.size(); i--;)
    00063         ungetToken(utf8[i]);
    00064     }
    00065     bool readLine(std::string& utf8)
    00066     {
    00067       utf8.clear();
    00068       if ( !inputFile()->isOpen() )
    00069         if(!inputFile()->open(OM_ReadOnly))
    00070           return false;
    00071
    00072       unsigned char ch = 0;
    00073       bool ok = false;
    00074       while( readToken(&ch) )
    00075       {
    00076         ok = true;
    00077         if ( ch == '\r' || ch == '\n' )
    00078         {
    00079           readToken(&ch);
    00080           if ( ch != '\r' && ch != '\n' )
    00081             ungetToken(ch);
    00082           break;
    00083         }
    00084         else
    00085           utf8 += ch;
    00086       }
    00087       return ok;
    00088     }
    00089
    00091     bool readLine(String& line)
    00092     {
    00093       line.clear();
    00094       std::vector<unsigned char> utf8;
    00095
    00096       if ( !inputFile()->isOpen() )
    00097         if(!inputFile()->open(OM_ReadOnly))
    00098           return false;
    00099
    00100       unsigned char ch = 0;
    00101       bool ok = false;
    00102       while( readToken(&ch) )
    00103       {
    00104         ok = true;
    00105         if ( ch == '\r' || ch == '\n' )
    00106         {
    00107           readToken(&ch);
    00108           if ( ch != '\r' && ch != '\n' )
    00109             ungetToken(ch);
    00110           break;
    00111         }
    00112         else
    00113           utf8.push_back(ch);
    00114       }
    00115       if(!utf8.empty())
    00116         line = String::fromUTF8((char*)&utf8[0], (int)utf8.size());
    00117       return ok;
    00118     }
    00119
    00121     bool readLineCR(String& line)
    00122     {
    00123       line.clear();
    00124       std::vector<unsigned char> utf8;
    00125
    00126       if ( !inputFile()->isOpen() )
    00127         if(!inputFile()->open(OM_ReadOnly))
    00128           return false;
    00129
    00130       unsigned char ch = 0;
    00131       while( readToken(&ch) )
    00132       {
    00133         if ( ch == '\r' )
    00134           break;
    00135         else
    00136           utf8.push_back(ch);
    00137       }
    00138       if(!utf8.empty())
    00139         line = String::fromUTF8((char*)&utf8[0], (int)utf8.size());
    00140       return !line.empty();
    00141     }
    00142
    00144     bool readLineLF(String& line)
    00145     {
    00146       line.clear();
    00147       std::vector<unsigned char> utf8;
    00148
    00149       if ( !inputFile()->isOpen() )
    00150         if(!inputFile()->open(OM_ReadOnly))
    00151           return false;
    00152
    00153       unsigned char ch = 0;
    00154       while( readToken(&ch) )
    00155       {
    00156         if ( ch == '\n' )
    00157           break;
    00158         else
    00159           utf8.push_back(ch);
    00160       }
    00161       if(!utf8.empty())
    00162         line = String::fromUTF8((char*)&utf8[0], (int)utf8.size());
    00163       return !line.empty();
    00164     }
    00165
    00166     bool readInt(int& i, bool hex=false);
    00167
    00168     bool readDouble(double& d);
    00169
    00170     bool readString(String& token)
    00171     {
    00172       token.clear();
    00173       unsigned char ch = 0;
    00174       while ( readToken(&ch) )
    00175       {
    00176         if ( ch == '\r' || ch == '\n' || ch == '\t' || ch == ' ' )
    00177         {
    00178           if ( token.empty() )
    00179             continue;
    00180           else
    00181             return true;
    00182         }
    00183         else
    00184           token += ch;
    00185       }
    00186       return !token.empty();
    00187     }
    00188
    00189     bool readStdString(std::string& token)
    00190     {
    00191       token.clear();
    00192       unsigned char ch = 0;
    00193       while ( readToken(&ch) )
    00194       {
    00195         if ( ch == '\r' || ch == '\n' || ch == '\t' || ch == ' ' )
    00196         {
    00197           if ( token.empty() )
    00198             continue;
    00199           else
    00200             return true;
    00201         }
    00202         else
    00203           token += ch;
    00204       }
    00205       return !token.empty();
    00206     }
    00207
    00208     bool readQuotedString(String& token)
    00209     {
    00210       bool open = false;
    00211       token.clear();
    00212       unsigned char ch = 0;
    00213       while ( readToken(&ch) )
    00214       {
    00215         // cannot be a multiline quote
    00216         if ( ch == '\r' || ch == '\n' || (!open && ( ch == '\t' || ch == ' ')) )
    00217         {
    00218           if ( token.empty() )
    00219             continue;
    00220           else
    00221             return true;
    00222         }
    00223         else
    00224           token += ch;
    00225
    00226         if (ch == '\"' || ch == '\'')
    00227           open = !open;
    00228       }
    00229       return !token.empty();
    00230     }
    00231
    00232   protected:
    00233     String mTmpStr;
    00234     std::string mTmpStdStr;
    00235   };
    00236 //-----------------------------------------------------------------------------
    00237 }
    00238
    00239 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:22.
Permission is granted to use this page to write and publish articles regarding Visualization Library.