00001 //<<<<<< INCLUDES >>>>>> 00002 00003 #include "Iguana/Models/interface/IgSimpleTextRep.h" 00004 #include "Iguana/Models/interface/IgTextModel.h" 00005 #include "Iguana/Framework/interface/IgRepContext.h" 00006 #include <classlib/utils/DebugAids.h> 00007 00008 //<<<<<< PRIVATE DEFINES >>>>>> 00009 //<<<<<< PRIVATE CONSTANTS >>>>>> 00010 //<<<<<< PRIVATE TYPES >>>>>> 00011 //<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> 00012 //<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> 00013 //<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> 00014 //<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> 00015 //<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> 00016 //<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> 00017 00018 IgSimpleTextRep::IgSimpleTextRep (IgTextModel *model, const std::string &text) 00019 : m_model (model), 00020 m_context (0), 00021 m_text (text) 00022 {} 00023 00024 IgSimpleTextRep::~IgSimpleTextRep (void) 00025 { 00026 // The destruction may come upon me in two ways: the object is 00027 // going away and the context is deleting me, or someone else 00028 // killed me. In the former case the caller will have done the 00029 // right thing of getting rid of references to me. However if my 00030 // context *was* deleted, I must not delete it again; if so, it 00031 // has already set its rep to null, which we use as a clue. 00032 00033 ASSERT (m_context); 00034 if (m_context->rep ()) 00035 { 00036 ASSERT (m_context->rep () == this); 00037 m_context->erase (false); 00038 delete m_context; 00039 } 00040 } 00041 00042 IgRepContext * 00043 IgSimpleTextRep::context (void) const 00044 { return m_context; } 00045 00046 void 00047 IgSimpleTextRep::context (IgRepContext *context) 00048 { ASSERT (! m_context); ASSERT (context); m_context = context; } 00049 00050 IgModel * 00051 IgSimpleTextRep::model (void) const 00052 { return m_model; } 00053 00054 const std::string & 00055 IgSimpleTextRep::text (void) const 00056 { return m_text; } 00057 00058 void 00059 IgSimpleTextRep::setText (const std::string &text) 00060 { m_text = text; if (m_model->text () == this) m_model->changed (); }