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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/Base/Io/SaveLoad/ValueSerializer.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 BaseModelValue portion of the Serializer class.
    00014
    00015
    00016 #include "Serializer.h"
    00017 #include <Mers/Utils/Io/SaveLoad/ISaveLoad.h>
    00018 #include <Mers/Models/Base/BaseModel.h>
    00019 #include <Mers/Models/Base/BaseModelValue.h>
    00020 #include <Mers/Utils/Lang/String.h>
    00021 #include <cassert>
    00022
    00024
    00025 using namespace Mers::Models::Base::Io::SaveLoad;
    00026 using Mers::Utils::Io::SaveLoad::ISaveLoad;
    00027 using Mers::Models::Base::BaseModel;
    00028 using Mers::Models::Base::BaseModelValue;
    00029 using Mers::Utils::Lang::String;
    00030
    00032
    00033 // Make this function completely local to this cpp file.
    00034 namespace {
    00035
    00040 static void saveLoadValueCommon( ISaveLoad * sl,
    00041         const BaseModelValue * value, String &name, unsigned int &uid )
    00042 {
    00043         // Must have a value if saving.
    00044         assert( sl->isLoading() || value != NULL );
    00045         // Value must have a valid name.
    00046         assert( sl->isLoading() || value->getName() != NULL );
    00047
    00048         // Get the data from the value.
    00049         if( sl->isSaving() ) {
    00050                 name = value->getName();
    00051                 uid = value->getUID();
    00052         }
    00053
    00054         // save/load the data.
    00055         sl->saveLoad( "name", name );
    00056         sl->saveLoad( "identifier", uid );
    00057 }
    00058
    00059 }
    00060
    00062
    00063 void Serializer::saveLoad( ISaveLoad * sl, const char *,
    00064         const BaseModelValue * &val )
    00065 {
    00066         String name;
    00067         unsigned int uid;
    00068
    00069         // Do the common portion
    00070         saveLoadValueCommon( sl, val, name, uid );
    00071
    00072         // If loading, create the BaseModelValue from the data.
    00073         if( sl->isLoading() ) {
    00074                 // Make a const value.
    00075                 BaseModelValue * unconstVal =
    00076                         new BaseModelValue( name, BaseModelValue::STRING );
    00077                 unconstVal->setUID( uid );
    00078                 assert( unconstVal != NULL );
    00079                 val = unconstVal;
    00080                 assert( val != NULL );
    00081         }
    00082 }
    00083
    00085
    00086 void Serializer::saveLoad( ISaveLoad * sl, const char *,
    00087         BaseModelValue * &val )
    00088 {
    00089         String name;
    00090         unsigned int uid;
    00091
    00092         // Do the common portion
    00093         saveLoadValueCommon( sl, val, name, uid );
    00094
    00095         // If loading, create the BaseModelValue from the data.
    00096         if( sl->isLoading() ) {
    00097                 // Make an unconst value.
    00098                 val = new BaseModelValue( name, BaseModelValue::STRING );
    00099                 assert( val != NULL );
    00100                 val->setUID( uid );
    00101         }
    00102 }
    00103
    00105