configuration_list.cpp

Go to the documentation of this file.
00001 #ifndef CONFIGURATION_LIST_IMPLEMENTATION_FILE
00002 #define CONFIGURATION_LIST_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : configuration_list                                                *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "amorph.cpp"
00019 #include "configlet.h"
00020 #include "configuration_list.h"
00021 
00022 #include <basis/istring.h>
00023 
00024 #ifndef EMBEDDED_BUILD
00025   #include <typeinfo>
00026 #endif
00027 
00028 class cl_figlet_list : public amorph<configlet> {};
00029 
00031 
00032 configuration_list::configuration_list()
00033 : _figs(new cl_figlet_list)
00034 {
00035 }
00036 
00037 configuration_list::~configuration_list()
00038 {
00039   WHACK(_figs);
00040 }
00041 
00042 void configuration_list::reset() { _figs->reset(); }
00043 
00044 void configuration_list::add(const configlet &new_item)
00045 {
00046   zap(new_item);
00047   _figs->append(new_item.duplicate());
00048 }
00049 
00050 const configlet *configuration_list::find(const configlet &to_find) const
00051 {
00052 #ifndef EMBEDDED_BUILD
00053   for (int i = 0; i < _figs->elements(); i++) {
00054     configlet &curr = *_figs->borrow(i);
00055     if ( (to_find.section() == curr.section())
00056         && (to_find.entry() == curr.entry())
00057         && (typeid(curr) == typeid(to_find)) ) {
00058       return &curr;
00059     }
00060   }
00061 #endif
00062   return NIL;
00063 }
00064 
00065 bool configuration_list::zap(const configlet &dead_item)
00066 {
00067   for (int i = 0; i < _figs->elements(); i++) {
00068     configlet &curr = *_figs->borrow(i);
00069     if ( (dead_item.section() == curr.section())
00070         && (dead_item.entry() == curr.entry()) ) {
00071       _figs->zap(i, i);
00072       return true;
00073     }
00074   }
00075   return false;
00076 }
00077 
00078 bool configuration_list::load(configurator &config)
00079 {
00080   bool to_return = true;
00081   for (int i = 0; i < _figs->elements(); i++) {
00082     configlet &curr = *_figs->borrow(i);
00083     if (!curr.load(config)) to_return = false;  // any failure is bad.
00084   }
00085   return to_return;
00086 }
00087 
00088 bool configuration_list::store(configurator &config) const
00089 {
00090   bool to_return = true;
00091   for (int i = 0; i < _figs->elements(); i++) {
00092     configlet &curr = *_figs->borrow(i);
00093     if (!curr.store(config)) to_return = false;  // any failure is bad.
00094   }
00095   return to_return;
00096 }
00097 
00098 
00099 #endif //CONFIGURATION_LIST_IMPLEMENTATION_FILE
00100 

Generated on Fri Nov 28 04:29:11 2008 for HOOPLE Libraries by  doxygen 1.5.1