/* $Revision: 5 $ $Date: 15/02/05 12:58 $ Copyright © 2004-2007, FSL Technologies Limited. Contact "http://fost.3.felspar.com". */ #include "stdafx.h" #include #include using namespace std; using namespace FSLib; namespace { Revision c_revision( L"$Archive: /FOST.3/F3Util/input.cpp $", __DATE__, L"$Revision: 5 $", L"$Date: 15/02/05 12:58 $" ); } /* FSLib::Input */ FSLib::Input::Input() { } FSLib::Input::~Input() { } _variant_t FSLib::Input::safe( const FSLib::wstring &n, const Nullable< size_t > &num, const FSLib::Nullable< FSLib::wstring > &partition, _variant_t def ) const { size_t ex( exists( n, partition ) ); if ( num.value( 0 ) < ex ) return value( n, num, partition ); else return def; } /* FSLib::InputSetting */ size_t InputSetting::exists( const FSLib::wstring &name, const FSLib::Nullable< FSLib::wstring > &partition ) const { return Setting::value( partition.value( L"Request" ), name, Null ) != Null ? 1 : 0; } _variant_t InputSetting::value( const FSLib::wstring &name, const Nullable< size_t > &num, const FSLib::Nullable< FSLib::wstring > &partition ) const { if ( !num.isnull() && num.value() ) throw FSLib::Exceptions::OutOfRange< size_t >( L"May not request a value for beyojnd index 0 in from an InputSetting", 0, 1, num.value() ); return _variant_t( Setting::value( partition.value( L"Request" ), name ).c_str() ); } /* FSLib::GenericInput */ FSLib::GenericInput::GenericInput( const t_data &d ) : m_data( d ) { } FSLib::GenericInput::t_name_iterator FSLib::GenericInput::begin() const { return m_data.begin(); } FSLib::GenericInput::t_name_iterator FSLib::GenericInput::end() const { return m_data.end(); } FSLib::GenericInput::t_value_iterator FSLib::GenericInput::begin( const t_name_iterator n ) const { return (*n).second.begin(); } FSLib::GenericInput::t_value_iterator FSLib::GenericInput::end( const t_name_iterator n ) const { return (*n).second.end(); } size_t FSLib::GenericInput::exists( const FSLib::wstring &n, const FSLib::Nullable< FSLib::wstring > & ) const { t_name_iterator pos = m_data.find( n ); if ( pos == end() ) return 0; else return (*pos).second.size(); } _variant_t FSLib::GenericInput::value( const FSLib::wstring &n, const Nullable< size_t > &num, const FSLib::Nullable< FSLib::wstring > &p ) const { if ( !exists( n, p ) ) throw FSLib::Exceptions::Field( L"Field does not exist in FORM data", concat( p, L"/", n ).value() ); else if ( num.value( 0 ) == 0 ) return *((*m_data.find( n )).second.begin()); else throw FSLib::Exceptions::NotImplemented( L"_variant_t FSLib::GenericInput::value( const FSLib::wstring &n, const Nullable< size_t > &num, const FSLib::Nullable< FSLib::wstring > &p ) const", L"Where num is not Null or not zero" ); }