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
00028 #ifndef SC_WRITER_POLICY_H_INCLUDED_
00029 #define SC_WRITER_POLICY_H_INCLUDED_
00030
00031 #if !defined(SC_DEFAULT_WRITER_POLICY)
00032 # if defined(SC_NO_WRITE_CHECK)
00033 # define SC_DEFAULT_WRITER_POLICY SC_UNCHECKED_WRITERS
00034 # else
00035 # define SC_DEFAULT_WRITER_POLICY SC_ONE_WRITER
00036 # endif
00037 #endif
00038
00039 namespace sc_core {
00040
00041 class sc_object;
00042 class sc_port_base;
00043 extern
00044 void
00045 sc_signal_invalid_writer( sc_object* target, sc_object* first_writer,
00046 sc_object* second_writer, bool check_delta );
00047
00048
00049
00050
00051
00052
00053
00054
00055 enum sc_writer_policy
00056 {
00057 SC_ONE_WRITER = 0,
00058 SC_MANY_WRITERS = 1,
00059 SC_UNCHECKED_WRITERS = 3
00060 };
00061
00062
00063 template< typename T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY >
00064 class sc_signal;
00065
00066 template< sc_writer_policy >
00067 struct sc_writer_policy_check;
00068
00069 struct sc_writer_policy_nocheck_write
00070 {
00071 bool check_write( sc_object* , bool )
00072 { return true; }
00073 void update(){}
00074 };
00075
00076 struct sc_writer_policy_check_write
00077 {
00078 bool check_write( sc_object* target, bool value_changed );
00079 void update(){}
00080 protected:
00081 sc_writer_policy_check_write( bool check_delta = false )
00082 : m_check_delta( check_delta ), m_writer_p(NULL) {}
00083 const bool m_check_delta;
00084 sc_object* m_writer_p;
00085 };
00086
00087 struct sc_writer_policy_check_delta
00088 : sc_writer_policy_check_write
00089 {
00090
00091 sc_writer_policy_check_delta()
00092 : sc_writer_policy_check_write(true) {}
00093
00094 bool check_write( sc_object* target, bool value_changed )
00095 {
00096 if( value_changed )
00097 return sc_writer_policy_check_write::check_write( target, true );
00098 return true;
00099 }
00100
00101 void update(){ m_writer_p = NULL; }
00102 };
00103
00104 struct sc_writer_policy_nocheck_port
00105 {
00106 bool check_port( sc_object*, sc_port_base*, bool )
00107 { return true; }
00108 };
00109
00110 struct sc_writer_policy_check_port
00111 {
00112 bool check_port( sc_object* target, sc_port_base* port, bool is_output );
00113
00114 protected:
00115 sc_writer_policy_check_port() : m_output(0) {}
00116 sc_port_base* m_output;
00117 };
00118
00119 template<>
00120 struct sc_writer_policy_check<SC_ONE_WRITER>
00121 : sc_writer_policy_check_port
00122 , sc_writer_policy_check_write
00123 {};
00124
00125 template<>
00126 struct sc_writer_policy_check<SC_MANY_WRITERS>
00127 : sc_writer_policy_nocheck_port
00128 , sc_writer_policy_check_delta
00129 {};
00130
00131 template<>
00132 struct sc_writer_policy_check<SC_UNCHECKED_WRITERS>
00133 : sc_writer_policy_nocheck_port
00134 , sc_writer_policy_nocheck_write
00135 {};
00136
00137 }
00138
00139 #endif
00140
00141