- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Models/Base/Io/SaveLoad/ModelSerializer.cpp

    00001
    00002 //
    00003 // Copyright (c) 2005           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #include "Serializer.h"
    00012 #include <Mers/Utils/Io/SaveLoad/ISaveLoad.h>
    00013 #include <Mers/Models/Base/BaseModel.h>
    00014 #include <Mers/Models/Base/BaseModelDomainArray.h>
    00015 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00016 #include <Mers/Utils/Lang/String.h>
    00017 #include <cassert>
    00018
    00020
    00021 using namespace Mers::Models::Base::Io::SaveLoad;
    00022 using Mers::Utils::Io::SaveLoad::ISaveLoad;
    00023 using Mers::Models::Base::BaseModel;
    00024 using Mers::Models::Base::BaseModelDomainArray;
    00025 using Mers::Models::Base::BaseModelVariableArray;
    00026 using Mers::Utils::Lang::String;
    00027
    00029
    00030 void Serializer::saveLoad( ISaveLoad * sl, const char *, BaseModel * &model )
    00031 {
    00032         // Get the name of the model, if we have it.
    00033         String name;
    00034         if( sl->isSaving() ) {
    00035                 assert( model != NULL );
    00036                 name = model->getName();
    00037         }
    00038
    00039         // Get the name.
    00040         sl->saveLoad( "name", name );
    00041
    00042         // Construct our model, if needed, or set the name.
    00043         if( sl->isLoading() ) {
    00044                 if( model == NULL ) {
    00045                         model = new BaseModel( name );
    00046                         assert( model != NULL );
    00047                 } else {
    00048                         assert( model != NULL );
    00049                         model->setName( name );
    00050                 }
    00051         }
    00052
    00053         // Set this as our current model
    00054         setModel( model );
    00055
    00056         // Save/Load our domains and variables
    00057         BaseModelDomainArray * domains(NULL);
    00058         BaseModelVariableArray * variables(NULL);
    00059         if( sl->isSaving() ) {
    00060                 domains = model->getDomains();
    00061                 variables = model->getVariables();
    00062         }
    00063
    00064         sl->saveLoad( domains, *this );
    00065         sl->saveLoad( variables, *this );
    00066
    00067         // If we're loading, then we need to clean up the memory of the
    00068         // two arrays (the data has already been added to the model),
    00069         // otherwise, we're done.
    00070         if( sl->isLoading() ) {
    00071                 assert( domains != NULL );
    00072                 assert( variables != NULL );
    00073                 delete domains;
    00074                 delete variables;
    00075         }
    00076 }
    00077
    00079