moab
FileOptions.hpp
Go to the documentation of this file.
00001 /*
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  * 
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
00007  * retains certain rights in this software.
00008  * 
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  * 
00014  */
00015 
00021 #ifndef FILE_OPTIONS_HPP
00022 #define FILE_OPTIONS_HPP
00023 
00024 #include <string>
00025 #include <vector>
00026 #include "moab/Types.hpp"
00027 
00028 namespace moab {
00029 
00036 class FileOptions {
00037 public:
00038 
00039   /*\param options_string The concatenation of a list of 
00040    *          options, separated either by the default separator
00041    *          (semicolon) with a custom separator specified at
00042    *          the beginning of the string (semicolon followed by
00043    *          destired separator character.)
00044    */
00045   FileOptions( const char* option_string);
00046   
00047   FileOptions( const FileOptions& copy );
00048   FileOptions& operator=( const FileOptions& copy );
00049   
00050   ~FileOptions();
00051   
00060   ErrorCode get_null_option( const char* name ) const;
00061   
00062   
00074   ErrorCode get_toggle_option( const char* name, 
00075                                bool default_value,
00076                                bool& value ) const;
00077    
00087   ErrorCode get_int_option( const char* name, int& value ) const;
00088   
00107   ErrorCode get_int_option( const char* name, int default_val, int& value ) const;
00108   
00118   ErrorCode get_real_option( const char* name, double& value ) const;
00119   
00129   ErrorCode get_str_option( const char* name, std::string& value ) const;
00130   
00138   ErrorCode get_option( const char* name, std::string& value ) const;
00139   
00152   ErrorCode match_option( const char* name, const char* const* values, int& index ) const;
00153   
00163   ErrorCode match_option( const char* name, const char* value) const;
00164   
00178   ErrorCode get_ints_option( const char* name, std::vector<int>& values) const;
00179   
00191   ErrorCode get_reals_option( const char* name, std::vector<double>& values) const;
00192   
00204   ErrorCode get_strs_option( const char* name, std::vector<std::string>& values) const;
00205   
00207   inline unsigned size() const 
00208     { return mOptions.size(); }
00209   
00211   inline bool empty() const 
00212     { return mOptions.empty(); }
00213   
00215   void get_options( std::vector<std::string>& list ) const;
00216   
00218   bool all_seen() const;
00219   
00221   void mark_all_seen() const;
00222   
00224   ErrorCode get_unseen_option( std::string& value ) const;
00225   
00226 private:
00227   
00235   ErrorCode get_option( const char* name, const char*& value) const;
00236 
00237   char* mData;
00238   std::vector<const char*> mOptions;
00239   mutable std::vector<bool> mSeen;
00240 
00242   static bool compare( const char* name, const char* option );
00243 };
00244   
00245 } // namespace moab
00246 
00247 #endif
00248 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines