Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/chancfg/chanparse.I

Go to the documentation of this file.
00001 // Filename: chanparse.I
00002 // Created by:  cary (06Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include <notify.h>
00020 
00021 INLINE void ChanEatFrontWhite(std::string& S) {
00022   size_t i = S.find_first_not_of(" \t\r\f\n");
00023   if ((i != std::string::npos) && (i != 0))
00024     S.erase(0, i);
00025 }
00026 
00027 INLINE void ChanCheckScoping(std::string& S) {
00028   if (S[0] != '(') {
00029     // error, unscoped text usually indicates a problem
00030     nout << "error, '" << S << "' does not start with a (" << endl;
00031     S.erase(0, S.find_first_of("("));
00032   }
00033 }
00034 
00035 INLINE void ChanDescope(std::string& S) {
00036   int i = ChanMatchingParen(S);
00037   nassertv(i != -1);
00038   S = S.substr(1, i-2);
00039   ChanEatFrontWhite(S);
00040 }
00041 
00042 INLINE std::string ChanReadNextWord(std::string& S) {
00043   int i = S.find_first_of(" \t\r\f\n");
00044   std::string stmp = S.substr(0, i);
00045   S.erase(0, i);
00046   ChanEatFrontWhite(S);
00047   return stmp;
00048 }
00049 
00050 INLINE int ChanReadNextInt(std::string& S) {
00051   int i = S.find_first_of(" \t\r\f\n");
00052   std::string stmp = S.substr(0, i);
00053   S.erase(0, i);
00054   ChanEatFrontWhite(S);
00055   istringstream st(stmp.c_str());
00056   st >> i;
00057   return i;
00058 }
00059 
00060 INLINE bool ChanReadNextBool(std::string& S) {
00061   int i = S.find_first_of(" \t\r\f\n");
00062   std::string stmp = S.substr(0, i);
00063   S.erase(0, i);
00064   ChanEatFrontWhite(S);
00065   bool ret = false;
00066   if ((stmp.length() != 2) || (stmp[0] != '#')) {
00067     // error, this isn't gonna be either #t or #f
00068     nout << "error, '" << stmp << "' is not either #t or #f" << endl;
00069     ret = false;
00070   }
00071   if (stmp[1] == 't')
00072     ret = true;
00073   else if (stmp[1] != 'f') {
00074     // error this isn't either #t or #f
00075     nout << "error, '" << stmp << "' is not either #t or #f" << endl;
00076     ret = false;
00077   }
00078   return ret;
00079 }
00080 
00081 // #f or int
00082 INLINE int ChanReadNextIntB(std::string& S) {
00083   int i = S.find_first_of(" \t\r\f\n");
00084   std::string stmp = S.substr(0, i);
00085   S.erase(0, i);
00086   ChanEatFrontWhite(S);
00087   i = -1;
00088   if (stmp[0] == '#')
00089     if ((stmp.length() != 2)||(stmp[1] != 'f')) {
00090       // error, not #f.. #t is not allowed in this case
00091       nout << "error, '" << stmp << "' is not allowed, only #f or an int"
00092            << endl;
00093       i = -1;
00094     }
00095   else {
00096     istringstream st(stmp.c_str());
00097     st >> i;
00098   }
00099   return i;
00100 }
00101 
00102 INLINE float ChanReadNextFloat(std::string& S) {
00103   int i = S.find_first_of(" \t\r\f\n");
00104   std::string stmp = S.substr(0, i);
00105   S.erase(0, i);
00106   ChanEatFrontWhite(S);
00107   istringstream st(stmp.c_str());
00108   float ret;
00109   st >> ret;
00110   return ret;
00111 }

Generated on Fri May 2 00:35:18 2003 for Panda by doxygen1.3