Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArConfigGroup.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArConfigGroup.h"
00029 #include "ArArgumentBuilder.h"
00030 #include "ArLog.h"
00031 
00032 AREXPORT ArConfigGroup::ArConfigGroup(const char *baseDirectory)
00033 {
00034   if (baseDirectory != NULL)
00035     myBaseDirectory = baseDirectory;
00036   else
00037     myBaseDirectory = "";
00038 }
00039 
00040 AREXPORT ArConfigGroup::~ArConfigGroup(void)
00041 {
00042   
00043 }
00044 
00045 AREXPORT void ArConfigGroup::addConfig(ArConfig *config)
00046 {
00047   myConfigs.push_back(config);
00048 }
00049 
00050 AREXPORT void ArConfigGroup::remConfig(ArConfig *config)
00051 {
00052   myConfigs.remove(config);
00053 }
00054 
00055 AREXPORT bool ArConfigGroup::parseFile(const char *fileName, 
00056                        bool continueOnError)
00057 {
00058   std::list<ArConfig *>::iterator it;
00059   bool ret = true;
00060 
00061   myLastFile = fileName;
00062   // go through all the configs and set the base directory (we don't
00063   // do it when we're parsing just so that whether it suceeds or fails
00064   // its the same behavior in this base directory regard)
00065   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00066   {
00067     (*it)->setBaseDirectory(myBaseDirectory.c_str());
00068   }
00069   // now we go through and parse files... if we get an error we stop
00070   // if we're supposed to
00071   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00072   {
00073     if (!(*it)->parseFile(fileName, continueOnError))
00074     {
00075       // if we are continuing on errors we still want to tell them we
00076       // had an error
00077       ret = false;
00078       // if we aren't continuing on error then just return
00079       if (!continueOnError)
00080     return false;
00081     }
00082   }
00083   return ret;
00084 }
00085 
00086 AREXPORT bool ArConfigGroup::reloadFile(bool continueOnError)
00087 {
00088   return parseFile(myLastFile.c_str(), continueOnError);
00089 }
00090 
00091 AREXPORT bool ArConfigGroup::writeFile(const char *fileName)
00092 {
00093   std::set<std::string> alreadyWritten;
00094   std::list<ArConfig *>::iterator it;
00095   bool ret = true;
00096   bool append = false;
00097   
00098   // go through all the configs and set the base directory (we don't
00099   // do it when we're parsing just so that whether it suceeds or fails
00100   // its the same behavior in this base directory regard)
00101   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00102   {
00103     (*it)->setBaseDirectory(myBaseDirectory.c_str());
00104   }
00105   // now we go through and parse files... if we get an error we stop
00106   // if we're supposed to
00107   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00108   {
00109     ArLog::log(ArLog::Verbose, "Writing config file");
00110     if (!(*it)->writeFile(fileName, append, &alreadyWritten))
00111     {
00112       // if we are continuing on errors we still want to tell them we
00113       // had an error
00114       ret = false;
00115     }
00116     append = true;
00117   }
00118   return ret;
00119   
00120 }
00121 
00122 AREXPORT void ArConfigGroup::setBaseDirectory(const char *baseDirectory)
00123 {
00124   myBaseDirectory = baseDirectory;
00125 }
00126 
00127 AREXPORT const char *ArConfigGroup::getBaseDirectory(void) const
00128 {
00129   return myBaseDirectory.c_str();
00130 }

Generated on Tue Feb 20 10:51:39 2007 for Aria by  doxygen 1.4.0