settings.h

Engine/source/util/settings.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SETTINGS_H_
 25#define _SETTINGS_H_
 26
 27#include "console/simBase.h"
 28#include "core/util/tVector.h"
 29
 30class SimXMLDocument;
 31
 32///
 33class Settings : public SimObject
 34{
 35private:
 36   FileName         mFile;
 37   Vector<String>   mGroupStack;
 38   S32              mSearchPos;
 39   Vector<String>   mSearchResults;
 40
 41public:
 42   Settings();
 43   virtual ~Settings();
 44
 45   // Required in all ConsoleObject subclasses.
 46   typedef SimObject Parent;
 47   DECLARE_CONOBJECT(Settings);
 48   static void initPersistFields();
 49
 50   /// These will set and get the values, with an option default value passed in to the get 
 51   void setDefaultValue(const UTF8 *settingName, const UTF8 *settingValue, const UTF8 *settingType="");
 52   void setValue(const UTF8 *settingName, const UTF8 *settingValue = "");
 53   const UTF8 *value(const UTF8 *settingName, const UTF8 *defaultValue = "");
 54   void remove(const UTF8 *settingName, bool includeDefaults = false);
 55   void clearAllFields();
 56   bool write();
 57   bool read();
 58   void readLayer(SimXMLDocument *document, String groupStack = String(""));
 59
 60   void beginGroup(const UTF8 *groupName, bool fromStart = false);
 61   void endGroup();
 62   void clearGroups();
 63   
 64   void buildGroupString(String &name, const UTF8 *settingName);
 65   const UTF8 *getCurrentGroups();
 66
 67   //S32 buildSearchList(const char* pattern, bool deepSearch = false, bool defaultsSearch = false);
 68   const char* findFirstValue(const char* pattern, bool deepSearch = false, bool includeDefaults = false);
 69   const char* findNextValue();
 70};
 71
 72class SettingSaveNode
 73{
 74public:
 75   Vector<SettingSaveNode*> mGroupNodes;
 76   Vector<SettingSaveNode*> mSettingNodes;
 77
 78   String mName;
 79   String mValue;
 80   bool mIsGroup;
 81
 82   SettingSaveNode()
 83   {
 84      mIsGroup = false;
 85   }
 86   SettingSaveNode(const String &name, bool isGroup = false)
 87   {
 88      mName = name;
 89      mIsGroup = isGroup;
 90   }
 91   SettingSaveNode(const String &name, const String &value)
 92   {
 93      mName = name;
 94      mValue = value;
 95      mIsGroup = false;
 96   }
 97   ~SettingSaveNode()
 98   {
 99      clear();
100   }
101
102   void addValue(const UTF8 *name, const UTF8 *value);
103   S32 getGroupCount(const String &name);
104   String getGroup(const String &name, S32 num);
105   String getSettingName(const String &name);
106   void buildDocument(SimXMLDocument *document, bool skipWrite = false);
107
108   void clear();
109};
110
111#endif
112