change.H

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 #ifndef ARCHON_X3D_SAI_CHANGE_H
00020 #define ARCHON_X3D_SAI_CHANGE_H
00021 
00022 #include <archon/x3d/server/event.H>
00023 
00024 namespace Archon
00025 {
00026   namespace X3D
00027   {
00028     namespace SAI
00029     {
00030       using namespace Utilities;
00031 
00032       struct ChangeBase: virtual RefObjectBase
00033       {
00034         virtual void apply(Time t) const = 0;
00035       };
00036 
00037       struct FieldSetChange: ChangeBase
00038       {
00039         FieldSetChange(Ref<NodeBase> node, const FieldBase *field,
00040                        Ref<const ValueBase> value):
00041           node(node), field(field), value(value) {}
00042 
00043         Ref<NodeBase> node;
00044         const FieldBase *field;
00045         Ref<const ValueBase> value;
00046 
00047         void apply(Time t) const
00048         {
00049           Event e(value, t);
00050           node->set(field, &e);
00051         }
00052       };
00053 
00054       struct FieldSetAtChange: ChangeBase
00055       {
00056         FieldSetAtChange(Ref<NodeBase> node, const SequenceFieldBase *field,
00057                          Ref<const ValueBase> value, unsigned index):
00058           node(node), field(field), value(value), index(index) {}
00059 
00060         Ref<NodeBase> node;
00061         const SequenceFieldBase *field;
00062         Ref<const ValueBase> value;
00063         unsigned index;
00064 
00065         void apply(Time t) const
00066         {
00067           node->setAt(field, value, index, t);
00068         }
00069       };
00070 
00071       struct FieldListChange: ChangeBase
00072       {
00073         FieldListChange(Ref<NodeBase> node, const SequenceFieldBase *field,
00074                         Ref<const ValueBase> value, bool remove = false):
00075           node(node), field(field), value(value), remove(remove) {}
00076 
00077         Ref<NodeBase> node;
00078         const SequenceFieldBase *field;
00079         Ref<const ValueBase> value;
00080         bool remove;
00081 
00082         void apply(Time t) const
00083         {
00084           if(remove) node->remove(field, value, t);
00085           else node->add(field, value, t);
00086         }
00087       };
00088 
00089       struct RouteChange: ChangeBase
00090       {
00091         RouteChange(Ref<NodeBase> sourceNode, const FieldBase *sourceField,
00092                     Ref<NodeBase> targetNode, const FieldBase *targetField,
00093                     bool remove = false):
00094           sourceNode(sourceNode), sourceField(sourceField),
00095           targetNode(targetNode), targetField(targetField),
00096           remove(remove) {}
00097 
00098         Ref<NodeBase> sourceNode;
00099         const FieldBase *sourceField;
00100         Ref<NodeBase> targetNode;
00101         const FieldBase *targetField;
00102         bool remove;
00103 
00104         void apply(Time) const
00105         {
00106           if(remove) Route::del(sourceNode, sourceField,
00107                                 targetNode, targetField);
00108           else Route::add(sourceNode, sourceField,
00109                           targetNode, targetField);
00110         }
00111       };
00112     }
00113   }
00114 }
00115 
00116 #endif // ARCHON_X3D_SAI_CHANGE_H

Generated on Sun Jul 30 22:55:48 2006 for Archon by  doxygen 1.4.4