00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanView.h"
00028
00029
00030 #include "CeylanLogPlug.h"
00031 #include "CeylanOperators.h"
00032
00033 #include "CeylanModel.h"
00034
00035 #ifdef CEYLAN_USES_CONFIG_H
00036 #include "CeylanConfig.h"
00037 #endif // CEYLAN_USES_CONFIG_H
00038
00039
00040 #include <list>
00041
00042
00043 using std::string ;
00044 using std::list ;
00045
00046
00047 using namespace Ceylan ;
00048 using namespace Ceylan::Log ;
00049
00050
00051
00052 View::View() :
00053 CallerEventListener()
00054 {
00055
00056 }
00057
00058
00059
00060 View::View( Model & model ) :
00061 CallerEventListener( static_cast<EventSource &>( model ) )
00062 {
00063
00064 }
00065
00066
00067
00068 View::~View() throw()
00069 {
00070
00071 #if CEYLAN_DEBUG_EVENTS
00072 LogPlug::debug( "Deleting View " + toString() ) ;
00073 #endif // CEYLAN_DEBUG_EVENTS
00074
00075 }
00076
00077
00078
00079 const string View::toString( Ceylan::VerbosityLevels level ) const
00080 {
00081
00082 if ( _sources.empty() )
00083 return "MVC View currently not subscribed to any model" ;
00084 else
00085 return "MVC View currently subscribed to "
00086 + Ceylan::toString(
00087 static_cast<Ceylan::Uint32>( _sources.size() ) )
00088 + " model(s)" ;
00089
00090 }
00091
00092
00093
00094
00095
00096
00097 Model & View::getModel()
00098 {
00099
00100 if ( _sources.size() != 1 )
00101 throw EventException( "View::getModel failed: "
00102 + Ceylan::toString( _sources.size() )
00103 + " model(s) associated to that view." ) ;
00104
00105 return * dynamic_cast<Model *>( _sources.front() ) ;
00106
00107 }
00108