osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser 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 * This program 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 Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 #include <osgEarthSymbology/CssUtils> 00020 #include <osgEarth/StringUtils> 00021 #include <iostream> 00022 #include <sstream> 00023 #include <iterator> 00024 00025 using namespace osgEarth; 00026 using namespace osgEarth::Symbology; 00027 00028 Config 00029 CssUtils::readConfig( std::istream& in ) 00030 { 00031 // read the entire stream into a string: 00032 std::stringstream buf; 00033 //std::copy( std::istreambuf_iterator<char>(in), //::istream_iterator<char>(in), 00034 // std::istreambuf_iterator<char>(), 00035 // std::ostreambuf_iterator<char>( buf ) ); 00036 00037 buf << in.rdbuf(); 00038 00039 std::string css; 00040 css = buf.str(); 00041 00042 // tokenize the CSS into a config object.. 00043 Config conf( "css" ); 00044 00045 StringTokenizer blockIzer( "{}", "" ); 00046 blockIzer.addQuotes( "'\"", true ); 00047 00048 StringTokenizer propSetIzer( ";", "" ); 00049 propSetIzer.addQuotes( "'\"", true ); 00050 00051 StringTokenizer propIzer( ":", "'\"" ); 00052 propIzer.addQuotes( "()", true ); 00053 00054 StringVector blocks; 00055 blockIzer.tokenize( css, blocks ); 00056 00057 for( unsigned i=0; i<blocks.size(); ) 00058 { 00059 const std::string& name = blocks[i++]; 00060 if ( i < blocks.size() ) 00061 { 00062 Config elementConf( name ); 00063 00064 StringVector propSet; 00065 propSetIzer.tokenize( blocks[i++], propSet ); 00066 00067 for( unsigned j=0; j<propSet.size(); ++j ) 00068 { 00069 StringVector prop; 00070 propIzer.tokenize( propSet[j], prop ); 00071 00072 if ( prop.size() == 2 ) 00073 { 00074 elementConf.attr( prop[0] ) = prop[1]; 00075 } 00076 } 00077 conf.add( elementConf ); 00078 } 00079 } 00080 00081 return conf; 00082 }