/* $Revision: 1 $ $Date: 6/11/04 21:49 $ Copyright © 2004-2006, FSL Technologies Limited. Contact "http://fost3.fsltech.com". */ #include "stdafx.h" #include "FOST.yaml.hpp" #include using namespace FSLib; namespace { Revision c_header( FOST_YAML_HPP_ARCHIVE, __DATE__, FOST_YAML_HPP_REVISION, FOST_YAML_HPP_DATE ); Revision c_revision( L"$Archive: /FOST.3/F3Util/record.cpp $", __DATE__, L"$Revision: 1 $", L"$Date: 6/11/04 21:49 $" ); const Setting c_filepath( L"$Archive: /FOST.3/F3Util/record.cpp $", L"Log", L"File path", L"c:\\FSLog.yaml.txt", true ); Mutex &g_log_mutex() { static Mutex m; return m; } Log &g_logFile() { Mutex::Lock lock( g_log_mutex() ); static boost::scoped_ptr< Log > log; if ( !log ) { wstring fn = c_filepath.value(); wstring::size_type filestart = fn.find_last_of( L"\\/" ); if ( filestart == std::wstring::npos ) filestart = 0; wstring::size_type extstart = fn.find_last_of( L'.' ); if ( extstart < filestart || extstart == std::wstring::npos ) log.reset( new Log( fn + L"." + TimeStamp::now().asString( TimeStamp::e_file_name ) + L".txt" ) ); log.reset( new Log( fn.substr( 0, extstart ) + L"." + TimeStamp::now().asString( TimeStamp::e_file_name ) + fn.substr( extstart ) ) ); } return *log; } } /* FSLib::YAML::Record */ YAML::Record &FSLib::YAML::Record::add( const wstring &name, t_null ) { m_content.push_back( std::make_pair( 0, name + L": ~" ) ); return *this; } YAML::Record &FSLib::YAML::Record::add( const wstring &name, const wstring &value ) { m_content.push_back( std::make_pair( 0, name + L": " + value ) ); return *this; } YAML::Record &FSLib::YAML::Record::add( const wstring &name, const Record &value ) { m_content.push_back( std::make_pair( 0, name + L": [" ) ); for ( std::list< std::pair< unsigned int, wstring > >::const_iterator it( value.m_content.begin() ); it != value.m_content.end(); ++it ) { m_content.push_back( std::make_pair( (*it).first + 1, (*it).second ) ); } m_content.push_back( std::make_pair( 0, L"]" ) ); return *this; } void FSLib::YAML::Record::log() const { wlogstream s( g_logFile().stream() ); printOn( s ) << std::endl; } std::wostream &FSLib::YAML::Record::printOn( std::wostream &o ) const { o << L"\n---\n# " << TimeStamp::now() << std::endl; for ( std::list< std::pair< unsigned int, wstring > >::const_iterator it( m_content.begin() ); it != m_content.end(); ++it ) o << wstring( (*it).first * 2, L' ' ) << (*it).second << std::endl; return o; }