Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/io/config_file.h

Go to the documentation of this file.
00001 //  Copyright (C) 2002  Petter Urkedal (petter.urkedal@matfys.lth.se)
00002 //
00003 //  This file is free software; you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation; either version 2 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  This file is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with this program; if not, write to the Free Software
00015 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 //
00017 //  As a special exception, you may use this file as part of a free
00018 //  software library without restriction.  Specifically, if other files
00019 //  instantiate templates or use macros or inline functions from this
00020 //  file, or you compile this file and link it with other files to
00021 //  produce an executable, this file does not by itself cause the
00022 //  resulting executable to be covered by the GNU General Public
00023 //  License.  This exception does not however invalidate any other
00024 //  reasons why the executable file might be covered by the GNU General
00025 //  Public License.
00026 //
00027 //  $Id: config_file.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00028 
00029 #ifndef MORE_IO_CONFIG_FILE_H
00030 #define MORE_IO_CONFIG_FILE_H
00031 
00032 #include <more/gen/ntree.h>
00033 
00034 namespace more {
00035 namespace io {
00036 
00037   /** The content of a configuration file is here represented as a
00038    ** tree of strings with a special interpretation.  A configuration
00039    ** file usually consists of a sequence of (key, value) assignments.
00040    ** Some configuration files also have sections and subsections.
00041    ** The respresentation is as follows.  A branch which has
00042    ** sub-branches is a section named by the node value.  If the
00043    ** branch has no sub-branches, it is an assignment.  The node value
00044    ** of the branch is the key and the leaves are its values.  The
00045    ** tree root is an anonymous section (its node value is an empty
00046    ** string).  Empty sections, other than the root, invalidates the
00047    ** tree, and must be removed by the parser or filled with a dummy
00048    ** assignment like '' = ''. */
00049   typedef gen::ntree<std::string> config_tree;
00050 
00051   /** True iff the \a t configuration subtree is a value (leaf). */
00052   inline bool
00053   is_config_value(config_tree const& t)
00054   {
00055       return t.branches().empty();
00056   }
00057 
00058   /** True iff the \a t configuration subtree is an assignment (branch
00059    ** with only leaves). */
00060   inline bool
00061   is_config_assignment(config_tree const& t)
00062   {
00063       return !t.branches().empty()
00064           && t.branches().begin()->branches().empty();
00065   }
00066 
00067   /** True iff the \a t configuration subtree is a section. */
00068   inline bool
00069   is_config_section(config_tree const& t)
00070   {
00071       return !t.branches().empty()
00072           && !t.branches().begin()->branches().empty();
00073   }
00074 
00075   /** True if \a t is a valid configuration tree.  Config file parsers
00076    ** should return valid configuration trees, so this is mostly
00077    ** useful for debugging parsers.  */
00078   bool is_valid_config_tree(config_tree const& t);
00079 
00080   // --- config_file_simple.cc ---
00081 
00082   /** Read config file in key-space-value-newline format.  The
00083    ** top-level branches are appended to \a t_out. */
00084   void read_config_ksvn(config_tree& t_out, std::string const& file_name);
00085 
00086   /** Read config file in key-equal-value-newline format.  The
00087    ** top-level branches are appended to \a t_out. */
00088   void read_config_kevn(config_tree& t_out, std::string const& file_name);
00089 
00090 }} // more::io
00091 
00092 #endif

Generated on Sat Sep 7 19:11:15 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.