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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/Base/Io/SaveLoad/DomainSerializer.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
    00012 // This file implements the BaseModelDomain portion of the Serializer
    00013 // class.
    00015
    00016
    00017 #include "Serializer.h"
    00018 #include <Mers/Utils/Io/SaveLoad/ISaveLoad.h>
    00019 #include <Mers/Models/Base/BaseModel.h>
    00020 #include <Mers/Models/Base/BaseModelDomain.h>
    00021 #include <Mers/Utils/Lang/String.h>
    00022 #include <cassert>
    00023
    00025
    00026 using namespace Mers::Models::Base::Io::SaveLoad;
    00027 using Mers::Utils::Io::SaveLoad::ISaveLoad;
    00028 using Mers::Models::Base::BaseModel;
    00029 using Mers::Models::Base::BaseModelDomain;
    00030 using Mers::Utils::Lang::String;
    00031
    00033
    00034 void Serializer::saveLoad( ISaveLoad * sl, const char *,
    00035         BaseModelDomain * &domain )
    00036 {
    00037         // Note that we could (should?) use the objName to specialize
    00038         // our domain type automatically, since they're different
    00039         // objects, and then use a factory to create the right one.
    00040         String name;
    00041         String domainType;
    00042
    00043         // Get the data from the domain.
    00044         if( sl->isSaving() ) {
    00045                 assert( domain != NULL );
    00046                 name = domain->getName();
    00047                 domainType =
    00048                         BaseModelDomain::domainTypeToString( domain->getDomainType() );
    00049         }
    00050
    00051         // save/load the data.
    00052         sl->saveLoad( "name", name );
    00053         sl->saveLoad( "domain_type", domainType );
    00054
    00055         // If loading, load the BaseModelDomain data and then create it.
    00056         if( sl->isLoading() ) {
    00057                 // Load the values.
    00058                 BaseModelValueArray * values( NULL );
    00059                 sl->saveLoad( values, *this );
    00060                 assert( values != NULL );
    00061
    00062                 // Translate our domain type.
    00063                 BaseModelDomain::DomainType domType;
    00064                 if( FAILED( BaseModelDomain::stringToDomainType(
    00065                         domainType, domType ) ) )
    00066                 {
    00067                         // Default to Normal
    00068                         domType = BaseModelDomain::Normal;
    00069                         // Log an error.
    00070                         assert( "Domain type was unknown." && false );
    00071                 }
    00072
    00073                 // Make sure we have a model.
    00074                 assert( m_model != NULL );
    00075
    00076                 // Make a domain.
    00077                 m_model->addDomain( name, *values, domType );
    00078                 domain = m_model->getDomain( name );
    00079                 assert( domain != NULL );
    00080
    00081                 // Delete our values.
    00082                 delete values;
    00083         } else {
    00084                 // We're saving the data, so just save domain.
    00085                 BaseModelValueArray * values = domain;
    00086                 assert( values != NULL );
    00087                 sl->saveLoad( values, *this );
    00088         }
    00089 }
    00090
    00092