00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #else
00023 #include "config.h"
00024 #endif
00025 #include "CallStack.h"
00026
00027 #include "Settings.h"
00028 #include "ConfigLexer.h"
00029
00030 namespace FIX
00031 {
00032 std::istream& operator>>( std::istream& stream, Settings& s )
00033 {
00034 ConfigLexer lexer( &stream );
00035 int lcState = 0;
00036 Settings::Sections::iterator currentSection = s.m_sections.end();
00037 std::string currentName;
00038 while ( 0 != ( lcState = lexer.yylex() ) )
00039 {
00040 switch ( lcState )
00041 {
00042 case ConfigLexer::LC_STATE_SECTION:
00043 currentSection = s.m_sections.insert
00044 ( s.m_sections.end(),
00045 Dictionary( lexer.YYText() ) );
00046 break;
00047 case ConfigLexer::LC_STATE_NAME:
00048 currentName = lexer.YYText();
00049 break;
00050 case ConfigLexer::LC_STATE_VALUE:
00051 std::string value = lexer.YYText();
00052 std::string::size_type pos = value.find_last_not_of( ' ' );
00053 if ( pos == std::string::npos ) continue;
00054 value.resize( pos + 1 );
00055 ( *currentSection ).setString( currentName, value );
00056 break;
00057 }
00058 }
00059 return stream;
00060 }
00061
00062 Settings::Sections Settings::get( std::string name ) const
00063 { QF_STACK_PUSH(Settings::get)
00064
00065 Sections sections;
00066 for ( Sections::size_type i = 0; i < m_sections.size(); ++i )
00067 if ( m_sections[ i ].getName() == name )
00068 sections.push_back( m_sections[ i ] );
00069 return sections;
00070
00071 QF_STACK_POP
00072 }
00073 }