CMS 3D CMS Logo

IgRepSet.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Framework/interface/IgRepSet.h"
00004 #include "Iguana/Framework/interface/IgRepContext.h"
00005 #include "Iguana/Framework/interface/IgBrowserMethods.h"
00006 #include "Iguana/Framework/interface/IgRepresentable.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 
00019 IgRepSet::LookupTable &
00020 IgRepSet::table (void)
00021 {
00022     static LookupTable table;
00023     return table;
00024 }
00025 
00027 IgRepSet::IgRepSet (IgRepresentable *object)
00028     : m_object (object),
00029       m_first (0)
00030 {}
00031 
00034 IgRepSet::~IgRepSet (void)
00035 {
00036     VERIFY (table ().erase (m_object) == 1);
00037 
00038     // Get rid of contexts
00039     while (m_first)
00040         delete m_first;
00041 }
00042 
00045 void
00046 IgRepSet::add (IgRepContext *context)
00047 {
00048     ASSERT (context);
00049     ASSERT (context != m_first);
00050 
00051     if (! m_first)
00052     {
00053         context->chain (context);
00054         m_first = context;
00055     }
00056     else
00057     {
00058         IgRepContext *last = m_first;
00059         while (last->next () != m_first)
00060         {
00061             ASSERT (last->next () != context);
00062             last = last->next ();
00063         }
00064         context->chain (m_first);
00065         last->chain (context);
00066     }
00067 }
00068 
00070 void
00071 IgRepSet::remove (IgRepContext *context)
00072 {
00073     ASSERT (m_first);
00074     ASSERT (context);
00075 
00076     IgRepContext *previous = m_first;
00077     IgRepContext *pos = m_first->next ();
00078 
00079     while (pos != context)
00080     {
00081         ASSERT (pos);
00082         previous = pos;
00083         pos = pos->next ();
00084     }
00085 
00086     ASSERT (pos == context);
00087     ASSERT (previous->next () == context);
00088 
00089     IgRepContext *next = pos->next ();
00090     if (previous == context)
00091     {
00092         // the list is only context long, and `context' is its only element
00093         ASSERT (m_first == context);
00094         ASSERT (m_first->next () == m_first);
00095         m_first = 0;
00096     }
00097     else
00098     {
00099         // unchain this context
00100         previous->chain (next);
00101         if (m_first == context)
00102             m_first = next;
00103     }
00104     context->chain (0);
00105 }
00106 
00109 IgRepContext *
00110 IgRepSet::lookup (IgModel *model) const
00111 {
00112     ASSERT (model);
00113 
00114     IgRepContext *context = m_first;
00115     do {
00116         if (! context)
00117             return 0;
00118 
00119         if (context->model () == model)
00120             return context;
00121 
00122         context = context->next ();
00123     } while (context != m_first);
00124 
00125     return 0;
00126 }
00127 
00131 IgRepSet *
00132 IgRepSet::associate (IgRepresentable *object, bool create /* = false */)
00133 {
00134     LookupTable &lookup_table = table ();
00135     LookupTable::iterator pos = lookup_table.find (object);
00136 
00137     if (pos != lookup_table.end ())
00138     {
00139         ASSERT (pos->second);
00140         return pos->second;
00141     }
00142     else if (create)
00143     {
00144         IgRepSet *&set = lookup_table [object];
00145         set = new IgRepSet (object);
00146         return set;
00147     }
00148     else
00149         return 0;
00150 }
00151 
00156 IgRep *
00157 IgRepSet::lookup (IgRepresentable *object, IgModel *model, bool create)
00158 {
00159     IgRepSet     *set = IgRepSet::associate (object, create);
00160     IgRepContext *context = set ? set->lookup (model) : 0;
00161 
00162     if (! context && create)
00163         context = IgBrowserMethods::represent (object, model);
00164 
00165     return context ? context->rep () : 0;
00166 }
00167 
00173 IgRep *
00174 IgRepSet::lookup (IgRepContext *context, IgModel *model, bool create)
00175 {
00176     IgRepContext *other = context->next ();
00177 
00178     while (other != context && other->model () != model)
00179         other = other->next ();
00180 
00181     if (other->model () == model)
00182         return other->rep ();
00183     else if (create)
00184     {
00185         other = IgBrowserMethods::represent (context->object (), model);
00186         ASSERT (! other || other->model () == model);
00187         ASSERT (! other || other->rep ());
00188 
00189     }
00190 
00191     return other ? other->rep () : 0;
00192 }
00193 
00198 void
00199 IgRepSet::update (IgRepresentable *object, unsigned field)
00200 {
00201     // Check if the object has any representations
00202     IgRepSet *set = associate (object);
00203     if (! set)
00204         return;
00205 
00206     // Update all contexts
00207     IgRepContext *first = set->contexts ();
00208     IgRepContext *context = first;
00209 
00210     do
00211         IgBrowserMethods::update (object, context->rep (), field);
00212     while ((context = context->next ()) != first);
00213 }
00214 
00219 void
00220 IgRepSet::update (IgRepContext *context, unsigned field)
00221 {
00222     IgRepContext        *next = context->next ();
00223     IgRepresentable     *object = context->object ();
00224 
00225     for ( ; next != context; next = next->next ())
00226         IgBrowserMethods::update (object, next->rep (), field);
00227 }
00228 
00232 void
00233 IgRepSet::update (IgRepresentable *object,IgModel *model, unsigned field)
00234 {
00235     if (IgRep *rep = lookup (object, model, false))
00236         IgBrowserMethods::update (object, rep, field);
00237 }
00238 
00250 void
00251 IgRepSet::invalidate (IgRepresentable *object, unsigned field)
00252 {
00253     IgBrowserMethods::invalidate (object, 0, field);
00254 }
00255 
00259 void
00260 IgRepSet::invalidate (IgRepContext *context, unsigned field)
00261 {
00262     IgRepContext        *next = context->next ();
00263     IgRepresentable     *object = context->object ();
00264 
00265     for ( ; next != context; next = next->next ())
00266         IgBrowserMethods::invalidate (object, next->model (), field);
00267 }
00268 
00271 void
00272 IgRepSet::invalidate (IgRepresentable *object, IgModel *model, unsigned field)
00273 {
00274     IgBrowserMethods::invalidate (object, model, field);
00275 }

Generated on Tue Jun 9 17:38:29 2009 for CMSSW by  doxygen 1.5.4