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

ArConfigGroup.cpp

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
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 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArConfigGroup.h"
00030 #include "ArArgumentBuilder.h"
00031 #include "ArLog.h"
00032 
00033 ArConfigGroup::ArConfigGroup(const char *baseDirectory)
00034 {
00035   if (baseDirectory != NULL)
00036     myBaseDirectory = baseDirectory;
00037   else
00038     myBaseDirectory = "";
00039 }
00040 
00041 ArConfigGroup::~ArConfigGroup(void)
00042 {
00043   
00044 }
00045 
00046 void ArConfigGroup::addConfig(ArConfig *config)
00047 {
00048   myConfigs.push_back(config);
00049 }
00050 
00051 void ArConfigGroup::remConfig(ArConfig *config)
00052 {
00053   myConfigs.remove(config);
00054 }
00055 
00056 bool ArConfigGroup::parseFile(const char *fileName, 
00057                                        bool continueOnError)
00058 {
00059   std::list<ArConfig *>::iterator it;
00060   bool ret = true;
00061 
00062   myLastFile = fileName;
00063   // go through all the configs and set the base directory (we don't
00064   // do it when we're parsing just so that whether it suceeds or fails
00065   // its the same behavior in this base directory regard)
00066   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00067   {
00068     (*it)->setBaseDirectory(myBaseDirectory.c_str());
00069   }
00070   // now we go through and parse files... if we get an error we stop
00071   // if we're supposed to
00072   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00073   {
00074     if (!(*it)->parseFile(fileName, continueOnError))
00075     {
00076       // if we are continuing on errors we still want to tell them we
00077       // had an error
00078       ret = false;
00079       // if we aren't continuing on error then just return
00080       if (!continueOnError)
00081         return false;
00082     }
00083   }
00084   return ret;
00085 }
00086 
00087 bool ArConfigGroup::reloadFile(bool continueOnError)
00088 {
00089   return parseFile(myLastFile.c_str(), continueOnError);
00090 }
00091 
00092 bool ArConfigGroup::writeFile(const char *fileName)
00093 {
00094   std::set<std::string> alreadyWritten;
00095   std::list<ArConfig *>::iterator it;
00096   bool ret = true;
00097   bool append = false;
00098   
00099   // go through all the configs and set the base directory (we don't
00100   // do it when we're parsing just so that whether it suceeds or fails
00101   // its the same behavior in this base directory regard)
00102   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00103   {
00104     (*it)->setBaseDirectory(myBaseDirectory.c_str());
00105   }
00106   // now we go through and parse files... if we get an error we stop
00107   // if we're supposed to
00108   for (it = myConfigs.begin(); it != myConfigs.end(); it++)
00109   {
00110     ArLog::log(ArLog::Verbose, "Writing config file");
00111     if (!(*it)->writeFile(fileName, append, &alreadyWritten))
00112     {
00113       // if we are continuing on errors we still want to tell them we
00114       // had an error
00115       ret = false;
00116     }
00117     append = true;
00118   }
00119   return ret;
00120   
00121 }
00122 
00123 void ArConfigGroup::setBaseDirectory(const char *baseDirectory)
00124 {
00125   myBaseDirectory = baseDirectory;
00126 }
00127 
00128 const char *ArConfigGroup::getBaseDirectory(void) const
00129 {
00130   return myBaseDirectory.c_str();
00131 }

Generated on Wed Oct 19 12:56:34 2005 for Aria by  doxygen 1.4.0