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

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/CompiledME/CCMEReader/CCMEReader.cpp

    00001
    00002 //
    00003 // Copyright (c) 2002           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 //
    00009 // Author:                      Paul H. Elliott
    00010 // Organization:        Model-based Embedded and Robotic Systems Group
    00011 //                                      Massachusetts Institute of Technology
    00012 //
    00013 // CCMEReader class
    00014 //
    00016
    00017 #include "CCMEReader.h"
    00018
    00019 #include <Mers/Models/Base/BaseModel.h>
    00020 #include <Mers/Estimation/Discrete/Dissent.h>
    00021 #include <Mers/Estimation/Discrete/CompiledTransition.h>
    00022
    00023
    00024 using namespace Mers::Estimation::Discrete::CompiledME::CCMEReader;
    00025 using namespace Mers::Estimation::Discrete;
    00026 using Mers::Models::Base::BaseModel;
    00027 using std::fprintf;
    00028 using std::vector;
    00029
    00031
    00032 // Stuff related to Flex/Bison
    00033 extern BaseModel const * myCCMEBaseModel;
    00034 extern CCMEReader * myCCMEReader;
    00035 extern FILE * yyCCMEReaderin;
    00036
    00037 int yyCCMEReaderparse();
    00038
    00040
    00041 CCMEReader::CCMEReader()
    00042 {
    00043 }
    00044
    00046
    00047 CCMEReader::~CCMEReader()
    00048 {
    00049 }
    00050
    00052
    00053 int CCMEReader::loadCCMEFile(char const * filename, BaseModel const &model)
    00054 {
    00055         FILE * file;
    00056         int ret;
    00057
    00058         //verify they gave us a non null filename
    00059         if(!filename)
    00060                 return 2;
    00061
    00062         file = fopen(filename, "r");
    00063         if(!file)
    00064         {
    00065                 perror(filename);
    00066                 fprintf(stderr, "Error with the CCME file\n");
    00067                 return 3;
    00068         }
    00069
    00070         myCCMEBaseModel = &model;
    00071         myCCMEReader = this;
    00072         yyCCMEReaderin = file;
    00073         ret = yyCCMEReaderparse();
    00074         fclose(file);
    00075         myCCMEBaseModel = NULL;
    00076         myCCMEReader = NULL;
    00077         yyCCMEReaderin = NULL;
    00078         return ret;
    00079 }
    00080
    00082
    00083 char const * CCMEReader::ccmeFileTypeToString(CCMEFileType fileType)
    00084 {
    00085         switch(fileType) {
    00086         case CCMEText001:
    00087                 return "CCME Text File v1";
    00088         default:
    00089                 return NULL;
    00090         }
    00091 }
    00092
    00094
    00095 bool CCMEReader::isTextFileFormat(CCMEFileType fileType)
    00096 {
    00097         return (fileType & CCMETextFileType) != 0;
    00098 }
    00099
    00101
    00102 void CCMEReader::addDissent(Dissent const * dissent)
    00103 {
    00104         if(dissent != NULL) {
    00105                 dissents.push_back(dissent);
    00106         }
    00107 }
    00108
    00110
    00111 vector<Dissent const *> const & CCMEReader::getDissents() const
    00112 {
    00113         return dissents;
    00114 }
    00115
    00117
    00118 void CCMEReader::addTransition(CompiledTransition const * compiledTransition)
    00119 {
    00120         if(compiledTransition != NULL) {
    00121                 compiledTransitions.push_back(compiledTransition);
    00122         }
    00123 }
    00124
    00126
    00127 vector<CompiledTransition const *> const & CCMEReader::getTransitions() const
    00128 {
    00129         return compiledTransitions;
    00130 }
    00131
    00133
    00134 char const * CCMEReader::getCCMEFileHeader(CCMEFileType fileType)
    00135 {
    00136         // technically only binary files have headers, text files can't
    00137         // reliably be expected to have the header with the right spacing...
    00138         // however, if we're going to be writing a text file, we can return the
    00139         // header expected
    00140
    00141         switch(fileType) {
    00142         case CCMEText001:
    00143                 return "CCMEFileV1";
    00144         default:
    00145                 return NULL;
    00146         }
    00147 }
    00148
    00150