Beispiel #1
0
// ------------------------------------------------------------------------------------------
bool GetDefaultString(string &value,string filename, string name,bool dbg) 
{
	
	char t_str[SIZE];
	ifstream ifs(filename.c_str());
	
	if( !ifs ) { // open failed
		cerr << "cannot open file " << filename << endl;
		return false;
		}

	string separators("\t ");

   	string::size_type pos,pose;
	while ( ifs.getline(t_str,SIZE)) {
		if(dbg) cout << t_str << "  " << name << endl;
		string line = t_str;
		if (line.find_first_of("#") != (string::size_type)0 )
			if( (pos = line.find(name)) != string::npos ) {
				pos += name.size()+1;
				pose = line.find_first_of(separators,pos);
				value = line.substr(pos,pose);
				if(dbg) printf("Key: %s Value: '%s'\n",name.c_str(),value.c_str());
				return true;
				}
   	}
return false;
}
Beispiel #2
0
void GncTxImport::settings (const CsvTransImpSettings& settings)
{
    /* First apply file format as this may recreate the tokenizer */
    file_format (settings.m_file_format);
    /* Only then apply the other settings */
    m_settings = settings;
    multi_split (m_settings.m_multi_split);
    base_account (m_settings.m_base_account);
    encoding (m_settings.m_encoding);

    if (file_format() == GncImpFileFormat::CSV)
        separators (m_settings.m_separators);
    else if (file_format() == GncImpFileFormat::FIXED_WIDTH)
    {
        auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
        fwtok->columns (m_settings.m_column_widths);
    }
    try
    {
        tokenize(false);
    }
    catch (...)
    { };

    /* Tokenizing will clear column types, reset them here
     * based on the loaded settings.
     */
    std::copy_n (settings.m_column_types.begin(),
            std::min (m_settings.m_column_types.size(), settings.m_column_types.size()),
            m_settings.m_column_types.begin());

}
Beispiel #3
0
std::vector<std::string> Command::extractParams(const std::string &params)
{
    std::vector<std::string> paramsList;
    boost::char_separator<char> separators(" \t");
    boost::tokenizer<boost::char_separator<char> > tokenizer(params, separators);
    std::string token;
    
    for (boost::tokenizer<boost::char_separator<char> >::const_iterator it = tokenizer.begin();
         it != tokenizer.end(); ++it) {
        token = *it;
        boost::algorithm::trim(token);
        paramsList.push_back(token);
    }

    return paramsList;
}
Beispiel #4
0
void reader (const char* file_path,
             OutputIterator result) {
  typedef typename std::iterator_traits<OutputIterator>::value_type
                            integral_value_type;
  typedef boost::tokenizer<boost::char_separator<char> > tokenizer_type;
  boost::char_separator<char> separators(" ");

  std::ifstream in(file_path);
  if (!in.is_open()) { printf ("Could not open %s\n", file_path); return; }

  std::string current_line;
  while (getline(in,current_line)) {
    tokenizer_type tokens(current_line, separators);
    for (tokenizer_type::iterator token_iter = tokens.begin();
         token_iter != tokens.end(); 
         ++token_iter) {
      *result++=boost::lexical_cast<integral_value_type>(token_iter->c_str());
    }
  }
}
Beispiel #5
0
/** Sets the file format for the file to import, which
 *  may cause the file to be reloaded as well if the
 *  previously set file format was different and a
 *  filename was already set.
 *  @param format the new format to set
 *  @exception std::ifstream::failure if file reloading fails
 */
void GncTxImport::file_format(GncImpFileFormat format)
{
    if (m_tokenizer && m_settings.m_file_format == format)
        return;

    auto new_encoding = std::string("UTF-8");
    auto new_imp_file = std::string();

    // Recover common settings from old tokenizer
    if (m_tokenizer)
    {
        new_encoding = m_tokenizer->encoding();
        new_imp_file = m_tokenizer->current_file();
        if (file_format() == GncImpFileFormat::FIXED_WIDTH)
        {
            auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
            if (!fwtok->get_columns().empty())
                m_settings.m_column_widths = fwtok->get_columns();
        }
    }

    m_settings.m_file_format = format;
    m_tokenizer = gnc_tokenizer_factory(m_settings.m_file_format);

    // Set up new tokenizer with common settings
    // recovered from old tokenizer
    m_tokenizer->encoding(new_encoding);
    load_file(new_imp_file);

    // Restore potentially previously set separators or column_widths
    if ((file_format() == GncImpFileFormat::CSV)
        && !m_settings.m_separators.empty())
        separators (m_settings.m_separators);
    else if ((file_format() == GncImpFileFormat::FIXED_WIDTH)
        && !m_settings.m_column_widths.empty())
    {
        auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
        fwtok->columns (m_settings.m_column_widths);
    }

}
Beispiel #6
0
//	---------------------------------------------------------------------------
HRESULT STDMETHODCALLTYPE CGraphATTSVGHandler::endElement( 
	const wchar_t *pwchNamespaceUri,
	int cchNamespaceUri,
	const wchar_t *pwchLocalName,
	int cchLocalName,
	const wchar_t *pwchQName,
	int cchQName)
{ 
	Element &e = m_stack.top();

	if (m_valid == true) {
		if (0 == e.m_tag.compare(_T("g"))) 
		{
			if (m_subgraph)
			{
				ATLASSERT(m_mode!=NEATO_MODE_SUBGRAPH_TREE);
				setBoundingBox(m_subgraph);
			}	
			else if(m_vertex)
			{
				setBoundingBox(m_vertex);
			}
			else if(m_edge)
			{
				// we don't care about edge points in this mode
				if(m_mode!=NEATO_MODE_SUBGRAPH_TREE)
				{
					CComQIPtr<IEdgeRenderer> renderer = m_canvas->GetRenderer(m_edge);
					if (renderer) {
						if (m_text_count)
						{
							GraphTypes::PointF pointF (m_text_x / m_text_count, m_text_y / m_text_count);
							pointF.x = (pointF.x * m_canvas->m_dpiXbase) / m_dpi;
							pointF.y = (pointF.y * m_canvas->m_dpiYbase) / m_dpi;
							renderer->SetLabelPos(GraphTypes::RectF(pointF, GraphTypes::SizeF()), GraphTypes::screen);
						}
						GraphTypes::PointFVector epts;
						if (m_meta->GetMetaSplines()) {
							for (PointList::iterator itr = m_points.begin(); itr != m_points.end(); ++itr)
							{
								GraphTypes::PointF pointF (itr->first, itr->second);
								pointF.x = (pointF.x * m_canvas->m_dpiXbase) / m_dpi;
								pointF.y = (pointF.y * m_canvas->m_dpiYbase) / m_dpi;
								epts.push_back(pointF);
							}
							renderer->SetPoints(epts, GraphTypes::screen);
						}
						else
						{
							renderer->SetPoints(epts, GraphTypes::screen);
						}
					}
				}
			}
		}
		else if (0 == e.m_tag.compare(_T("title"))) {
			m_title = e.GetContent();
		}
		else if (0 == e.m_tag.compare(_T("text")))  {
			m_text  = e.GetContent();
			try
			{
				m_text_x += boost::lexical_cast<GraphTypes::REAL>(e.m_attr[_T("x")]);
				m_text_y += boost::lexical_cast<GraphTypes::REAL>(e.m_attr[_T("y")]);
				++m_text_count;
			}
			catch (boost::bad_lexical_cast &)
			{
				m_text_x = 0;
				m_text_y = 0;
			}
		}
		else { 
			std::string content;

			if (0 == e.m_tag.compare(_T("polygon"))) {
				content = CT2A(e.m_attr[_T("points")].c_str());
			}
			else if (0 == e.m_tag.compare(_T("path"))) {
				content = CT2A(e.m_attr[_T("d")].c_str());
			}

			if (content.length()) {
				boost::char_separator<char>  separators ("AaCcHhLlMmQqSsTtVvZz, ");	// svg codes & separators
				boost::tokenizer<boost::char_separator<char> > tokens(content,separators);
				boost::tokenizer<boost::char_separator<char> >::iterator itr = tokens.begin();

				while (itr != tokens.end()) {
					try
					{
						float x = boost::lexical_cast<float>((*itr++));
						float y = boost::lexical_cast<float>((*itr++));
						m_points.push_back(std::pair<GraphTypes::REAL, GraphTypes::REAL>(x, y));
					}
					catch (boost::bad_lexical_cast &)
					{
					}
				}
			}
		}
	}

	return __super::endElement(pwchNamespaceUri, cchNamespaceUri, pwchLocalName, cchLocalName, pwchQName, cchQName);
}
//*************************************************************************************************
//! Returns a projection corresponding to the group (e.g., "EPSG") and PCS code provided, 
//! or NULL if no entry found.
//*************************************************************************************************
ossimProjection* ossimEpsgProjectionDatabase::findProjection(const ossimString& spec) const
{
   ossimProjection* proj = 0;

   // Use the CRS code to access the database. The spec should be <group>:<code> where <group> is 
   // "EPSG" (the only group handled here):
   ossim_uint32 spec_code;
   ossimString spec_group ("epsg"); // default if only integer code provided
   if (spec.contains(":"))
   {
      spec_group = spec.before(":");
      spec_code = spec.after(":").toUInt32();
      spec_group = spec_group.downcase();
   }
   else
   {
      spec_code = spec.toUInt32();
   }

   // Presently only EPSG database is handled:
   if ((spec_code != 0) && (spec_group == "epsg"))
      return findProjection(spec_code);

   // The spec is probably a projection name. Need to search Db
   // by the projection name. Search database for entry. The spec may use different delimiters than
   // the DB so need to split the strings and compare the words:
   ossimString separators ("_ /()");
   vector<ossimString> split_spec = spec.split(separators, true);
   vector<ossimString> split_db_name;
   ossimRefPtr<ossimMapProjection> map_proj = 0;
   std::multimap<ossim_uint32, ossimRefPtr<ProjDbRecord> >::iterator db_iter = m_projDatabase.begin();
   while ((db_iter != m_projDatabase.end()) && !proj)
   {
      ProjDbRecord* db_record = db_iter->second.get();
      split_db_name.clear();
      split_db_name = db_record->name.split(separators, true);
      if (split_spec == split_db_name)
      {
         // We may already have instantiated this projection, in which case just return its copy.
         // Otherwise, create the projection from the EPSG code that corresponds to the name:
         if (db_record->proj.valid())
            proj = (ossimMapProjection*) db_record->proj->dup();
         else
            proj = findProjection(db_record->code);
         return proj;
      }
      db_iter++;
   }
    
   // No hit? Could be that just a datum was identified, in which case we need a simple 
   // Platte Carree:
   const ossimDatum* datum = ossimDatumFactoryRegistry::instance()->create(spec);
   if (datum)
   {
      ossimEquDistCylProjection* proj = new ossimEquDistCylProjection(*(datum->ellipsoid()));
      proj->setDatum(datum);
      proj->setPcsCode(spec_code);
      return proj;
   }

   return 0;
}
Beispiel #8
0
/*****************************************************************************
* First character of command id should be second char of line
* Lexer returns a full line of data, needs to be parsed if .ce
* In version 1.0, valid commands are:
* .* (comment) followed by text to '\n'
* .br (new line), nothing else allowed on line
* .im (include file) 'filename'
* .nameit (define text macro) symbol=[a-zA-Z0-9]+ (10 max) text='text string'
*     text may contain entity references, nameit references and tags
* .ce (center) no tags, but text and both entity types
* Version 2.0 only supports .*, .br, .im
*/
Lexer::Token Document::processCommand( Lexer* lexer, Tag* parent )
{
    if( lexer->cmdId() == Lexer::COMMENT )
        ;//do nothing
    else if( lexer->cmdId() == Lexer::BREAK )
        parent->appendChild( new BrCmd( this, parent, dataName(), dataLine(), dataCol() ) );
    else if( lexer->cmdId() == Lexer::CENTER ) {
        CeCmd* cecmd( new CeCmd( this, parent, dataName(), dataLine(), dataCol() ) );
        parent->appendChild( cecmd );
        return cecmd->parse( lexer );
    }
    else if( lexer->cmdId() == Lexer::IMBED ) {
        std::string env( Environment.value( "IPFCIMBED" ) );
        std::vector< std::wstring > paths;
        std::wstring cwd;   //empty string for current directory
        paths.push_back( cwd );
#ifdef __UNIX__
        std::string separators( ":;" );
        char slash( '/' );
#else
        std::string separators( ";" );
        char slash( '\\' );
#endif
        std::string::size_type idx1( 0 );
        std::string::size_type idx2( env.find_first_of( separators, idx1 ) );
        std::wstring fbuffer;
        mbtowstring( env.substr( idx1, idx2 - idx1 ), fbuffer );
        paths.push_back( fbuffer );
        while( idx2 != std::string::npos ) {
            idx1 = idx2 + 1;
            idx2 = env.find_first_of( separators, idx1 );
            fbuffer.clear();
            mbtowstring( env.substr( idx1, idx2 - idx1 ), fbuffer );
            paths.push_back( fbuffer );
        }
        for( size_t count = 0; count < paths.size(); ++count ) {
            std::wstring* fname( new std::wstring( paths[ count ] ) );
            if( !fname->empty() )
                *fname += slash;
            *fname += lexer->text();
#ifndef __UNIX__
            if( fname->size() > PATH_MAX ) {
                throw FatalError( ERR_PATH_MAX );
            }
#endif
            try {
                IpfFile* ipff( new IpfFile( fname ) );
                fname = addFileName( fname );
                pushInput( ipff );
                break;
            }
            catch( FatalError& e ) {
                delete fname;
                if( count == paths.size() - 1 )
                    throw e;
            }
            catch( FatalIOError& e ) {
                delete fname;
                if( count == paths.size() - 1 )
                    throw e;
            }
        }
    }
    else if( lexer->cmdId() == Lexer::NAMEIT ) {
        std::wstring::size_type idx1( lexer->text().find( L"symbol=" ) );
        std::wstring::size_type idx2( lexer->text().find( L' ', idx1 ) );
        std::wstring sym( lexer->text().substr( idx1 + 7, idx2 - idx1 - 7 ) );
        killQuotes( sym );
        sym.insert( sym.begin(), L'&' );
        sym += L'.';
        std::wstring::size_type idx3( lexer->text().find( L"text=" ) );
        //check for single quotes
        std::wstring::size_type idx4( lexer->text()[ idx3 + 5 ] == L'\'' ? \
            lexer->text().find( L'\'', idx3  + 6 ) : \
            lexer->text().find( L' ', idx3 + 5 ) );
        std::wstring txt( lexer->text().substr( idx3 + 5, idx4 - idx3 - 5 ) );
        killQuotes( txt );
        if( !nls->isEntity( sym ) && nameIts.find( sym ) == nameIts.end() ) //add it to the list
            nameIts.insert( std::map< std::wstring, std::wstring >::value_type( sym, txt ) );
        else
            printError( ERR3_DUPSYMBOL );
    }
    else
        printError( ERR1_CMDNOTDEF );
    return getNextToken();
}
Beispiel #9
0
void Document::makeBitmaps()
{
    if( !bitmapNames.empty() ) {
        //could use tmpfile...
        tmpName = Environment.value( "TMP" );
        tmpName += std::tmpnam( NULL );
        std::FILE* tmp( std::fopen( tmpName.c_str(), "wb" ) );
        if( !tmp )
            throw FatalIOError( ERR_OPEN, L"(temporary file for bitmaps)" );
        //get IPFCARTWORK from env
        std::string env( Environment.value( "IPFCARTWORK" ) );
        std::vector< std::string > paths;
        std::string cwd;    //empty string for current directory
        paths.push_back( cwd );
#ifdef __UNIX__
        std::string separators( ":;" );
        char slash( '/' );
#else
        std::string separators( ";" );
        char slash( '\\' );
#endif
        std::string::size_type idx1( 0 );
        std::string::size_type idx2( env.find_first_of( separators, idx1 ) );
        paths.push_back( env.substr( idx1, idx2 - idx1 ) );
        while( idx2 != std::string::npos ) {
            idx1 = idx2 + 1;
            idx2 = env.find_first_of( separators, idx1 );
            paths.push_back( env.substr( idx1, idx2 - idx1 ) );
        }
        try {
            for( BitmapNameIter itr = bitmapNames.begin(); itr != bitmapNames.end(); ++itr ) {
                std::string fname;
                wtombstring( itr->first, fname );
                for( size_t count = 0; count < paths.size(); ++count ) {
                    std::string fullname( paths[ count ] );
                    if( !fullname.empty() )
                        fullname += slash;
                    fullname += fname;
#ifndef __UNIX__
                    if( fullname.size() > PATH_MAX ) {
                        throw FatalError( ERR_PATH_MAX );
                    }
#endif
                    try {
#ifdef CHECKCOMP
                        std::printf( "Processing bitmap %s\n", fullname.c_str() );
#endif
                        Bitmap bm( fullname );
                        itr->second = bm.write( tmp );
                        break;
                    }
                    catch( FatalError& e ) {
                        if( count == paths.size() - 1 )
                            throw FatalIOError( e.code, itr->first );
                    }
                    catch( Class1Error& e ) {
                        printError( e.code, itr->first );
                    }
                }
            }
        }
        catch( FatalError& e ) {
            std::fclose( tmp );
            std::remove( tmpName.c_str() );
            throw e;
        }
        catch( FatalIOError& e ) {
            std::fclose( tmp );
            std::remove( tmpName.c_str() );
            throw e;
        }
        std::fclose( tmp );
    }
}