Commit 84b7cd18 authored by fogal1's avatar fogal1

Add some functions for looking up runtime parameters.

This adds a `RuntimeSettings' namespace which has functions for
easily configuring and looking up runtime parameters.  The
important consideration this implementation handles is finding
parameters from multiple places.

Settings are given a compile time default, and metadata such as
associated environment variables and command line options.  The
search defaults to the compile-time value, but successively looks
for settings which are more specific for the user.

The current ordering, from most important/specific to least, is:
  command line options
  environment variable
  configuration file entry (unimplemented)
  compile-time default

Adding a new parameter is as simple as adding a new entry to a
struct within the implementation.  There is a framework in place
to look up integer, double, boolean, and string values.  String
values are a bit special: if they begin with '.', we prepend
VisIt's installation directory to them.  This allows one to store
settings which point to directories or files.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@8011 18c085ea-50e0-402c-830e-de6fd14e8384
parent 55983b2b
......@@ -73,6 +73,9 @@
# Mark C. Miller, Tue Apr 21 14:37:24 PDT 2009
# Added DebugStreamFull.[Ch] (really a rename of DebugStream.[Ch])
#
# Tom Fogal, Sat Jun 27 19:44:13 MDT 2009
# Added RuntimeSetting.
#
# Tom Fogal, Tue Jun 30 19:54:23 MDT 2009
# Add define for proper symbol export.
#
......@@ -91,9 +94,11 @@ CPPFLAGS=-I. @CPPFLAGS@ -DMISC_EXPORTS
## Files...
##
SRC=DebugStreamFull.C Environment.C FileFunctions.C InstallationFunctions.C \
PTY.C StackTimer.C TimingsManager.C VisItException.C VisItInit.C
HDR=DebugStreamFull.h DebugStream.h Environment.h FileFunctions.C InstallationFunctions.h \
PTY.h StackTimer.h TimingsManager.h VisItException.h VisItInit.h
PTY.C RuntimeSetting.C StackTimer.C TimingsManager.C VisItException.C \
VisItInit.C
HDR=DebugStreamFull.h DebugStream.h Environment.h FileFunctions.C \
InstallationFunctions.h PTY.h RuntimeSetting.h StackTimer.h \
TimingsManager.h VisItException.h VisItInit.h
OBJ=$(SRC:.C=.o)
LIB=libmisc
......
This diff is collapsed.
/*****************************************************************************
*
* Copyright (c) 2000 - 2009, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// RuntimeSetting.h //
// ************************************************************************* //
#ifndef VISIT_RUNTIME_SETTING_H
#define VISIT_RUNTIME_SETTING_H
#include <misc_exports.h>
#include <string>
// A runtime setting is an abstraction for obtaining configuration information.
// There is a precedence order for obtaining preferences:
// 1. defaults hardcoded at compile time
// 2. values set in a configuration file
// 3. obtained from an environment variable
// 4. specified via a command line option
// Later values override earlier settings.
namespace RuntimeSetting
{
// ****************************************************************************
// Function: RuntimeSetting::lookup
//
// Purpose: Looks up a value
//
// Programmer: Tom Fogal
// Creation: June 25, 2009
//
// ****************************************************************************
int MISC_API lookupi(const char *key);
double MISC_API lookupf(const char *key);
std::string MISC_API lookups(const char *key);
bool MISC_API lookupb(const char *key);
// ****************************************************************************
// Function: RuntimeSetting::parse_command_line
//
// Purpose: Creates overrides based on command line parameters.
//
// Programmer: Tom Fogal
// Creation: June 25, 2009
//
// ****************************************************************************
void MISC_API parse_command_line(int argc, const char *argv[]);
};
#endif // VISIT_RUNTIME_SETTING_H
../../common/misc/RuntimeSetting.h
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment