URNResolver.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __URNRESOLVER_H__
00030 #define __URNRESOLVER_H__
00031 
00032 #include "H3DApi.h"
00033 #include <map>
00034 #include <fstream>
00035 #include <iostream>
00036 #include <string>
00037 
00038 using namespace std;
00039 
00040 namespace H3D {
00062   class H3DAPI_API URNResolver {
00063   public:
00064 
00065     
00068     URNResolver( const string &_config_file = "" ){
00069       config_file = _config_file;
00070       initialised = false;
00071     }
00072 
00074     void loadConfigFile( const string &config_file );
00075 
00081     void addURNResolveRule( const string &name_space,
00082                             const string &prefix,
00083                             const string &path ) {
00084       string key = "urn:";
00085       key = key + toLower( name_space ) + ":" + prefix;
00086       urn_prefix_map[ key ] = path;
00087     }
00088 
00089 
00092     string resolveURN( const string &urn );
00093 
00094   protected:
00095 
00096     static const unsigned int MAX_LINE_SIZE = 1024;
00097     bool nonCaseEquals( const string &s1, 
00098                         const string &s2 ) {
00099       if( s1.size() != s2.size() ) return false;
00100       
00101       for( unsigned int i = 0; i < s1.size(); i++ ) {
00102         if( toupper( s1[i]) != toupper( s2[i] ) )
00103           return false;
00104       }
00105       return true;
00106     }
00107 
00108     bool hasPrefix( const string &s,
00109                     const string &prefix ) {
00110       if( prefix.size() > s.size() ) return false;
00111       for( unsigned int i = 0; i < prefix.size(); i++ )
00112         if( s[i] != prefix[i] ) return false;
00113       return true;
00114     }
00115 
00116     string toLower( const string &s ) {
00117       string res = s;
00118       for( unsigned int i = 0; i < s.size(); i++ )
00119         res[i] = tolower( s[i] );
00120       return res;
00121     }
00122 
00123     struct lessthan_string {
00124       bool operator()(const string & s1, const string & s2) const {
00125         if( s1.size() < s2.size() ) return true;
00126         return s1 < s2;
00127       }
00128     };
00129 
00130     typedef map< string, string, lessthan_string > URNmap;
00131     URNmap urn_prefix_map;
00132     string config_file;
00133     bool initialised;
00134   };
00135 }
00136 
00137 #endif

Generated on Thu Aug 24 12:38:35 2006 for H3D API by  doxygen 1.4.5