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   
 72};
 73
 74class SettingSaveNode
 75{
 76public:
 77   Vector<SettingSaveNode*> mGroupNodes;
 78   Vector<SettingSaveNode*> mSettingNodes;
 79
 80   String mName;
 81   String mValue;
 82   bool mIsGroup;
 83
 84   SettingSaveNode()
 85   {
 86      mIsGroup = false;
 87   }
 88   SettingSaveNode(const String &name, bool isGroup = false)
 89   {
 90      mName = name;
 91      mIsGroup = isGroup;
 92   }
 93   SettingSaveNode(const String &name, const String &value)
 94   {
 95      mName = name;
 96      mValue = value;
 97      mIsGroup = false;
 98   }
 99   ~SettingSaveNode()
100   {
101      clear();
102   }
103
104   void addValue(const UTF8 *name, const UTF8 *value);
105   S32 getGroupCount(const String &name);
106   String getGroup(const String &name, S32 num);
107   String getSettingName(const String &name);
108   void buildDocument(SimXMLDocument *document, bool skipWrite = false);
109
110   void clear();
111
112   static S32 _NodeCompare(SettingSaveNode* const* a, SettingSaveNode* const* b);
113};
114
115#endif
116