MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
objectsettings.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _objectsettings_cpp
41 #define _objectsettings_cpp
42 
43 #include "objectsettings.h"
44 #include "stringtool.h"
45 #include "resourcemanager.h"
46 #include "Resource/filestream.h"
47 
48 namespace Mezzanine
49 {
50  ///////////////////////////////////////////////////////////////////////////////
51  // ObjectSettingSetContainer Methods
52 
54  ContainerName(Name)
55  { }
56 
58  { this->DestroyAllObjectSettingSets(); }
59 
60  ///////////////////////////////////////////////////////////////////////////////
61  // Utility
62 
64  { this->ContainerName = Name; }
65 
67  { return ContainerName; }
68 
69  ///////////////////////////////////////////////////////////////////////////////
70  // Sub-Set Methods
71 
73  {
74  ObjectSettingSet* NewSubSet = new ObjectSettingSet( Name );
75  NewSubSet->ParentSetOrGroup = this;
76  this->SubSets.push_back( NewSubSet );
77  return NewSubSet;
78  }
79 
81  {
82  ToBeAdded->ParentSetOrGroup = this;
83  this->_MarkUpdated();
84  this->SubSets.push_back( ToBeAdded );
85  }
86 
88  {
89  for( ConstSubSetIterator it = this->SubSets.begin() ; it != this->SubSets.end() ; ++it )
90  {
91  if( Name == (*it)->GetName() ) {
92  if(0 == Which) return (*it);
93  else --Which;
94  }
95  }
96  return NULL;
97  }
98 
100  {
101  return this->SubSets.at(Index);
102  }
103 
105  {
106  for( SubSetIterator it = this->SubSets.begin() ; it != this->SubSets.end() ; ++it )
107  {
108  if( ToBeRemoved == (*it) ) {
109  ToBeRemoved->ParentSetOrGroup = NULL;
110  this->SubSets.erase(it);
111  this->_MarkUpdated();
112  return;
113  }
114  }
115  }
116 
118  {
119  for( SubSetIterator it = this->SubSets.begin() ; it != this->SubSets.end() ; ++it )
120  {
121  if( Name == (*it)->GetName() ) {
122  delete (*it);
123  this->SubSets.erase(it);
124  return;
125  }
126  }
127  }
128 
130  {
131  if( this->SubSets.empty() )
132  return;
133  for( SubSetIterator it = this->SubSets.begin() ; it != this->SubSets.end() ; ++it )
134  {
135  (*it)->ParentSetOrGroup = NULL;
136  delete (*it);
137  }
138  this->SubSets.clear();
139  }
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  // Iterator Access
143 
145  { return this->SubSets.begin(); }
146 
148  { return this->SubSets.begin(); }
149 
151  { return this->SubSets.end(); }
152 
154  { return this->SubSets.end(); }
155 
156  ///////////////////////////////////////////////////////////////////////////////
157  // ObjectSettingSet Methods
158 
161  ParentSetOrGroup(NULL)
162  { }
163 
165  { }
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // Utility
169 
171  { return this->ParentSetOrGroup; }
172 
173  ///////////////////////////////////////////////////////////////////////////////
174  // Setting Methods
175 
176  void ObjectSettingSet::SetSettingValue(const String& SettingName, const String& StringValue)
177  {
178  this->Settings.insert( std::pair<String,String>(SettingName,StringValue) );
179  this->_MarkUpdated();
180  }
181 
183  {
184  ConstSettingsIterator SetIt = this->Settings.find( SettingName );
185  if( SetIt != this->Settings.end() ) return (*SetIt).second;
186  else return "";
187  }
188 
189  ///////////////////////////////////////////////////////////////////////////////
190  // Iterator Access
191 
193  { return this->Settings.begin(); }
194 
196  { return this->Settings.begin(); }
197 
199  { return this->Settings.end(); }
200 
202  { return this->Settings.end(); }
203 
205  {
206  if( this->ParentSetOrGroup )
208  }
209 
210  ///////////////////////////////////////////////////////////////////////////////
211  // ObjectSettingGroup Methods
212 
215  OptionalFile(NULL)
216  { }
217 
219  { }
220 
221  ///////////////////////////////////////////////////////////////////////////////
222  // Optional File config
223 
225  { return this->OptionalFile; }
226 
228  { return ( this->OptionalFile ? this->OptionalFile->GetFileName() : StringTools::Blank ); }
229 
230  ///////////////////////////////////////////////////////////////////////////////
231  // Internal Methods
232 
234  {
235  if( this->OptionalFile )
236  this->OptionalFile->SetNeedsSave(true);
237  }
238 
240  {
241  this->OptionalFile = File;
242  this->_MarkUpdated();
243  }
244 
245  ///////////////////////////////////////////////////////////////////////////////
246  // ObjectSettingFile Methods
247 
249  File(FileName),
250  NeedsSave(false)
251  { }
252 
254  { }
255 
256  ///////////////////////////////////////////////////////////////////////////////
257  // File and Group Management
258 
260  { return this->File; }
261 
263  { this->NeedsSave = Save; }
264 
266  { return this->NeedsSave; }
267 
269  {
270  Group->_SetOptionalFile(this);
271  this->SaveGroups.push_back(Group);
272  this->NeedsSave = true;
273  }
274 
276  {
277  for( ConstSaveGroupsIterator SaveIt = this->SaveGroups.begin() ; SaveIt != this->SaveGroups.end() ; ++SaveIt )
278  {
279  if( Name == (*SaveIt)->GetName() )
280  return (*SaveIt);
281  }
282  return NULL;
283  }
284 
286  {
287  for( SaveGroupsIterator SaveIt = this->SaveGroups.begin() ; SaveIt != this->SaveGroups.end() ; ++SaveIt )
288  {
289  if( Group == (*SaveIt) ) {
290  Group->_SetOptionalFile(NULL);
291  this->SaveGroups.erase(SaveIt);
292  this->NeedsSave = true;
293  return;
294  }
295  }
296  }
297 
299  { return this->SaveGroups; }
300 
302  { return this->SaveGroups.begin(); }
303 
305  { return this->SaveGroups.begin(); }
306 
308  { return this->SaveGroups.end(); }
309 
311  { return this->SaveGroups.end(); }
312 
313  ///////////////////////////////////////////////////////////////////////////////
314  // ObjectSettingsHandler Methods
315 
317  AutoGenPath(true),
318  AutoGenFiles(true)
319  { }
320 
322  { }
323 
325  {
327  XML::Document SettingsDoc;
328  // Open the stream and load the document
329  try
330  {
331  /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready.
332  Resource::FileStream SettingsStream(FileName,Path);
333  SettingsDoc.Load(SettingsStream);
334  }
335  catch( FileNotFoundException Ex )
336  {
337  // File doesn't exist, just exit. If the user wants to autogen it will be autogen'd later.
338  return RetVec;
339  }
340 
341  // Load and parse the settings
342  XML::Node RootNode = SettingsDoc.GetChild(GetObjectRootNodeName());
343  if( !RootNode.Empty() ) {
344  XML::Node CurrentSettingsNode = RootNode.GetChild("Current");
345  if( !RootNode.Empty() ) {
346  if( !this->CurrentSettingsSaveFile.empty() ) {
347  MEZZ_EXCEPTION(Exception::II_DUPLICATE_IDENTITY_EXCEPTION,"Second file containing \"Current\" settings detected.");
348  }
349  this->CurrentSettingsSaveFile = FileName;
350  }
351 
352  // Store the settings for a moment, since we have some extra stuff to do with them.
353  RetVec = this->LoadSettingsFromXML(RootNode);
354 
355  ObjectSettingFile* NewSetFile = this->CreateSettingFile(FileName);
356  for( SettingGroupVector::iterator It = RetVec->begin() ; It != RetVec->end() ; ++It )
357  NewSetFile->AddGroup( (*It) );
358  return RetVec;
359  }else{
360  MEZZ_EXCEPTION(Exception::II_IDENTITY_INVALID_EXCEPTION,"Attempting to parse XML which does not contain valid ObjectRootNodeName. Searching for \"" + GetObjectRootNodeName() + "\", not found.");
361  }
362  }
363 
364  void ObjectSettingsHandler::SaveSettingsToFile(StringVector& GroupNames, const String& FileName, const String& Path)
365  {
366  XML::Document SettingsDoc;
367  XML::Node DeclNode = SettingsDoc.AppendChild(XML::NodeDeclaration);
368  XML::Attribute VerAttrib = DeclNode.AppendAttribute("version");
369  if( DeclNode.SetName("xml") && VerAttrib.SetValue("1.0") ) {
370  XML::Node RootNode = SettingsDoc.AppendChild( this->GetObjectRootNodeName() );
371 
372  if( GroupNames.empty() ) this->SaveSettingsToXML(RootNode);
373  else this->SaveSettingsToXML(GroupNames,RootNode);
374  // Open a stream to the saving file
375  /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready.
377  SettingsDoc.Save(SettingsStream,"\t",XML::FormatIndent);
378  }else{
379  MEZZ_EXCEPTION(Exception::INVALID_STATE_EXCEPTION,"Failed to create XML document declaration for file \"" + FileName + "\".");
380  }
381  }
382 
384  {
385  for( XML::AttributeIterator SettingIt = XMLNode.attributes_begin() ; SettingIt != XMLNode.attributes_end() ; ++SettingIt )
386  {
387  XML::Attribute CurrAttrib = (*SettingIt);
388  if( !CurrAttrib.Empty() )
389  Set->SetSettingValue(CurrAttrib.Name(),CurrAttrib.AsString());
390  }
391  for( XML::NodeIterator SubSetIt = XMLNode.begin() ; SubSetIt != XMLNode.end() ; ++SubSetIt )
392  {
393  XML::Node SubSetNode = (*SubSetIt);
394  ObjectSettingSet* NewSubSet = Set->CreateChildObjectSettingSet( SubSetNode.Name() );
395  this->LoadSettingSetFromXML( SubSetNode, NewSubSet );
396  }
397  }
398 
400  {
401  for( ObjectSettingSet::SettingsIterator SetIt = Set->SettingsBegin() ; SetIt != Set->SettingsEnd() ; ++SetIt )
402  {
403  XML::Attribute CurrAttrib = XMLNode.AppendAttribute( (*SetIt).first );
404  CurrAttrib.SetValue( (*SetIt).second );
405  }
406  for( ObjectSettingSetContainer::SubSetIterator SubSetIt = Set->SubSetBegin() ; SubSetIt != Set->SubSetEnd() ; ++SubSetIt )
407  {
408  XML::Node SubSetNode = XMLNode.AppendChild( (*SubSetIt)->GetName() );
409  this->SaveSettingSetToXML( SubSetNode, (*SubSetIt) );
410  }
411  }
412 
413  ///////////////////////////////////////////////////////////////////////////////
414  // Setting Group Handling
415 
417  {
418  SettingGroupIterator SetIt = this->SettingGroups.find(GroupName);
419  if( SetIt != this->SettingGroups.end() ) {
420  this->ApplySettingGroupImpl( (*SetIt).second );
421  }else{
422  MEZZ_EXCEPTION(Exception::II_IDENTITY_NOT_FOUND_EXCEPTION,"Setting Group \"" + GroupName + "\" not found when attempting to apply settings.");
423  }
424  }
425 
427  {
428  ObjectSettingGroup* NewGroup = new ObjectSettingGroup(Name);
429  this->SettingGroups.insert( std::pair<String,ObjectSettingGroup*>(Name,NewGroup) );
430  return NewGroup;
431  }
432 
434  {
435  ConstSettingGroupIterator SetIt = this->SettingGroups.find(Name);
436  if( SetIt != this->SettingGroups.end() ) return (*SetIt).second;
437  else return NULL;
438  }
439 
441  {
442  SettingGroupIterator SetIt = this->SettingGroups.find(Name);
443  if( SetIt != this->SettingGroups.end() ) {
444  delete (*SetIt).second;
445  this->SettingGroups.erase(SetIt);
446  }
447  }
448 
450  {
451  this->DestroySettingGroup( ToBeDestroyed->GetName() );
452  }
453 
455  {
456  for( SettingGroupIterator SetIt = this->SettingGroups.begin() ; SetIt != this->SettingGroups.end() ; ++SetIt )
457  {
458  delete (*SetIt).second;
459  }
460  this->SettingGroups.clear();
461  }
462 
463  ///////////////////////////////////////////////////////////////////////////////
464  // Setting File Handling
465 
467  {
468  ObjectSettingFile* NewFile = new ObjectSettingFile(FileName);
469  this->SettingFiles.insert( std::pair<String,ObjectSettingFile*>(FileName,NewFile) );
470  return NewFile;
471  }
472 
474  {
475  SettingFilesIterator SettingFileIt = this->SettingFiles.find(FileName);
476  if( SettingFileIt != this->SettingFiles.end() ) return (*SettingFileIt).second;
477  else return NULL;
478  }
479 
481  {
482  SettingFilesIterator SettingFileIt = this->SettingFiles.find(FileName);
483  if( SettingFileIt != this->SettingFiles.end() )
484  {
485  ObjectSettingFile* ToDestroy = (*SettingFileIt).second;
486  delete ToDestroy;
487  this->SettingFiles.erase(SettingFileIt);
488  }
489  }
490 
492  {
493  this->DestroySettingFile( ToBeDestroyed->GetFileName() );
494  }
495 
497  {
498  ObjectSettingFile* ToDestroy = NULL;
499  for( SettingFilesIterator SettingFileIt = this->SettingFiles.begin() ; SettingFileIt != this->SettingFiles.end() ; ++SettingFileIt )
500  {
501  ToDestroy = (*SettingFileIt).second;
502  delete ToDestroy;
503  }
504  this->SettingFiles.clear();
505  }
506 
508  {
509  ObjectSettingFile* GroupFile = NULL;
510  if( FileName.empty() )
511  return;
512 
513  SettingFilesIterator SettingFileIt = this->SettingFiles.find(FileName);
514  if( SettingFileIt != this->SettingFiles.end() ) GroupFile = (*SettingFileIt).second;
515  else
516  {
517  GroupFile = new ObjectSettingFile(FileName);
518  this->SettingFiles.insert( std::pair<String,ObjectSettingFile*>(FileName,GroupFile) );
519  }
520 
521  GroupFile->AddGroup(Group);
522  }
523 
524  void ObjectSettingsHandler::RemoveGroupFromFile(ObjectSettingGroup* Group, const String& FileName)
525  {
526  if( FileName.empty() )
527  return;
528 
529  SettingFilesIterator SettingFileIt = this->SettingFiles.find(FileName);
530  if( SettingFileIt != this->SettingFiles.end() ) (*SettingFileIt).second->RemoveGroup(Group);
531  else return;
532  }
533 
534  ///////////////////////////////////////////////////////////////////////////////
535  // Setting Path Handling
536 
537  void ObjectSettingsHandler::SetSettingsFilePath(const String& Path)
538  {
539  size_t FirstDol = Path.find_first_of('$');
540  size_t SecondDol = Path.find_first_of('$',FirstDol+1);
541  if(FirstDol != String::npos && SecondDol != String::npos) {
542  String PathKeyWord = Path.substr( FirstDol + 1, ( SecondDol - FirstDol ) - 1 );
543  String RestOfPath = Path.substr( SecondDol + 1 );
544  String ActualPath = ResourceManager::GetSingletonPtr()->ResolveDataPathFromString(PathKeyWord);
545  this->SettingsFilePath = ActualPath + RestOfPath;
546  }else{
547  this->SettingsFilePath = Path;
548  }
549 
550  if( this->AutoGenPath )
551  ResourceManager::GetSingletonPtr()->CreateDirectoryPath(this->SettingsFilePath);
552  }
553 
554  const String& ObjectSettingsHandler::GetSettingsFilePath() const
555  {
556  return this->SettingsFilePath;
557  }
558 
559  void ObjectSettingsHandler::SetCurrentSettingsSaveFile(const String& FileName)
560  {
561  this->CurrentSettingsSaveFile = FileName;
562  }
563 
564  ConstString& ObjectSettingsHandler::GetCurrentSettingsSaveFile() const
565  {
566  return this->CurrentSettingsSaveFile;
567  }
568 
569  ///////////////////////////////////////////////////////////////////////////////
570  // Loading Utilities
571 
572  CountedPtr<ObjectSettingsHandler::SettingGroupVector> ObjectSettingsHandler::LoadSettingsFromGroup(const String& FileName, const String& Group)
573  {
574  String FilePath = ResourceManager::GetSingletonPtr()->GetAssetPath(FileName,Group);
575  if( FilePath.empty() ) {
576  MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,"Failed to find path for file \"" + FileName + "\", in group \"" + Group + "\".");
577  }
578  return this->LoadSettingsFromFile(FileName,FilePath);
579  }
580 
581  CountedPtr<ObjectSettingsHandler::SettingGroupVector> ObjectSettingsHandler::LoadSettings(const String& FileName, const String& Path)
582  {
583  return this->LoadSettingsFromFile(FileName,Path);
584  }
585 
586  CountedPtr<ObjectSettingsHandler::SettingGroupVector> ObjectSettingsHandler::LoadSettings(const String& FileName)
587  {
588  if( this->SettingsFilePath.empty() ) {
589  MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,"Attempting to use a preset path that hasn't been set.");
590  }
591  return this->LoadSettingsFromFile(FileName,SettingsFilePath);
592  }
593 
594  CountedPtr<ObjectSettingsHandler::SettingGroupVector> ObjectSettingsHandler::LoadSettingsFromXML(XML::Node& RootSettings)
595  {
596  ObjectSettingGroup* SetAfter = NULL;
598  for( XML::NodeIterator CurrGroupIt = RootSettings.begin() ; CurrGroupIt != RootSettings.end() ; ++CurrGroupIt )
599  {
600  XML::Node CurrGroupNode = (*CurrGroupIt);
601  String SettingGroupName = CurrGroupNode.Name();
602  ObjectSettingGroup* NewGroup = new ObjectSettingGroup(SettingGroupName);
603  if( "Current" != SettingGroupName ) {
604  this->SettingGroups.insert( std::pair<String,ObjectSettingGroup*>(SettingGroupName,NewGroup) );
605  RetVec->push_back(NewGroup);
606  }else{
607  if(!SetAfter) SetAfter = NewGroup;
608  else { MEZZ_EXCEPTION(Exception::II_DUPLICATE_IDENTITY_EXCEPTION,"Multiple \"Current\" setting groups detected while loading settings."); }
609  }
610  for( XML::NodeIterator CurrSetIt = CurrGroupNode.begin() ; CurrSetIt != CurrGroupNode.end() ; ++CurrSetIt )
611  {
612  XML::Node CurrSetNode = (*CurrSetIt);
613  String SettingSetName = CurrSetNode.Name();
614  ObjectSettingSet* NewSet = NewGroup->CreateChildObjectSettingSet(SettingSetName);
615  this->LoadSettingSetFromXML( CurrSetNode, NewSet );
616  }
617  }
618  if(SetAfter) {
619  this->ApplySettingGroupImpl(SetAfter);
620  delete SetAfter;
621  }
622  return RetVec;
623  }
624 
625  ///////////////////////////////////////////////////////////////////////////////
626  // Saving Utilities
627 
628  void ObjectSettingsHandler::SetAutoGenPath(Boolean Enable)
629  { this->AutoGenPath = Enable; }
630 
631  Boolean ObjectSettingsHandler::GetAutoGenPath() const
632  { return this->AutoGenPath; }
633 
634  void ObjectSettingsHandler::SetAutoGenFiles(Boolean Enable)
635  { this->AutoGenFiles = Enable; }
636 
637  Boolean ObjectSettingsHandler::GetAutoGenFiles() const
638  { return this->AutoGenFiles; }
639 
640  void ObjectSettingsHandler::SaveAllSettings()
641  {
642  if( this->SettingsFilePath.empty() ) {
643  MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,"Attempting to use a preset path that hasn't been set.");
644  }
645 
646  StringVector GroupNames;
647  for( SettingFilesIterator SettingFileIt = this->SettingFiles.begin() ; SettingFileIt != this->SettingFiles.end() ; ++SettingFileIt )
648  {
649  ObjectSettingFile* CurrFile = (*SettingFileIt).second;
650  Boolean IsCurrentSettingsFile = ( CurrentSettingsSaveFile == CurrFile->GetFileName() );
651  if( CurrFile->GetNeedsSave() || IsCurrentSettingsFile ) {
652  if( IsCurrentSettingsFile )
653  GroupNames.push_back( "Current" );
654  for( ObjectSettingFile::SaveGroupsIterator SetGroupIt = CurrFile->SaveGroupsBegin() ; SetGroupIt != CurrFile->SaveGroupsEnd() ; ++SetGroupIt )
655  {
656  GroupNames.push_back( (*SetGroupIt)->GetName() );
657  }
658  this->SaveSettingsToFile(GroupNames,(*SettingFileIt).second->GetFileName(),SettingsFilePath);
659 
660  CurrFile->SetNeedsSave(false);
661  GroupNames.clear();
662  }
663  }
664  }
665 
666  void ObjectSettingsHandler::SaveSettingsByFile(const String& FileName, const String& Path)
667  {
668  StringVector GroupNames;
669  if( this->CurrentSettingsSaveFile == FileName )
670  GroupNames.push_back( "Current" );
671 
672  SettingFilesIterator SetFileIt = this->SettingFiles.find(FileName);
673  if( SetFileIt == this->SettingFiles.end() ) {
674  MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,"Setting file \"" + FileName + "\" was not found when attempting to save.");
675  }
676 
677  for( ObjectSettingFile::SaveGroupsIterator SetGroupIt = (*SetFileIt).second->SaveGroupsBegin() ; SetGroupIt != (*SetFileIt).second->SaveGroupsEnd() ; ++SetGroupIt )
678  {
679  GroupNames.push_back( (*SetGroupIt)->GetName() );
680  }
681  this->SaveSettingsToFile(GroupNames,FileName,Path);
682  (*SetFileIt).second->SetNeedsSave(false);
683  }
684 
685  void ObjectSettingsHandler::SaveSettingsByFile(const String& FileName)
686  {
687  if( this->SettingsFilePath.empty() ) {
688  MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,"Attempting to use a preset path that hasn't been set.");
689  }
690 
691  StringVector GroupNames;
692  if( this->CurrentSettingsSaveFile == FileName )
693  GroupNames.push_back( "Current" );
694 
695  SettingFilesIterator SetFileIt = this->SettingFiles.find(FileName);
696  if( SetFileIt == this->SettingFiles.end() ) {
697  MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,"Setting file \"" + FileName + "\" was not found when attempting to save.");
698  }
699 
700  for( ObjectSettingFile::SaveGroupsIterator SetGroupIt = (*SetFileIt).second->SaveGroupsBegin() ; SetGroupIt != (*SetFileIt).second->SaveGroupsEnd() ; ++SetGroupIt )
701  {
702  GroupNames.push_back( (*SetGroupIt)->GetName() );
703  }
704  this->SaveSettingsToFile(GroupNames,FileName,SettingsFilePath);
705  (*SetFileIt).second->SetNeedsSave(false);
706  }
707 
708  void ObjectSettingsHandler::SaveSettingGroups(StringVector& GroupNames, const String& FileName, const String& Path)
709  {
710  this->SaveSettingsToFile(GroupNames,FileName,Path);
711  }
712 
713  void ObjectSettingsHandler::SaveSettingGroups(StringVector& GroupNames, const String& FileName)
714  {
715  if( this->SettingsFilePath.empty() ) {
716  MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,"Attempting to use a preset path that hasn't been set.");
717  }
718 
719  this->SaveSettingsToFile(GroupNames,FileName,SettingsFilePath);
720  }
721 
722  void ObjectSettingsHandler::SaveSettingsToXML(XML::Node& RootSettings, Boolean SaveCurrent)
723  {
724  StringVector GroupNames;
725 
726  if(SaveCurrent)
727  GroupNames.push_back( "Current" );
728 
729  for( SettingGroupIterator GroupNameIt = this->SettingGroups.begin() ; GroupNameIt != this->SettingGroups.end() ; ++GroupNameIt )
730  {
731  GroupNames.push_back( (*GroupNameIt).first );
732  }
733  this->SaveSettingsToXML(GroupNames,RootSettings);
734  }
735 
736  void ObjectSettingsHandler::SaveSettingsToXML(StringVector& GroupNames, XML::Node& RootSettings)
737  {
738  for( StringVector::iterator StrIt = GroupNames.begin() ; StrIt != GroupNames.end() ; ++StrIt )
739  {
740  if( "Current" == (*StrIt) ) {
741  this->AppendCurrentSettings(RootSettings);
742  }else{
743  SettingGroupIterator GroupIt = this->SettingGroups.find( (*StrIt) );
744  if( GroupIt == this->SettingGroups.end() ) {
745  MEZZ_EXCEPTION(Exception::II_IDENTITY_NOT_FOUND_EXCEPTION,"Attempting to save setting group \"" + (*StrIt) + "\", which does not exist.");
746  }
747  ObjectSettingSetContainer* SaveSet = (*GroupIt).second;
748  XML::Node GroupNode = RootSettings.AppendChild( (*GroupIt).first );
749  for( ObjectSettingSetContainer::SubSetIterator SubSetIt = SaveSet->SubSetBegin() ; SubSetIt != SaveSet->SubSetEnd() ; ++SubSetIt )
750  {
751  XML::Node SetNode = GroupNode.AppendChild( (*SubSetIt)->GetName() );
752  this->SaveSettingSetToXML( SetNode, (*SubSetIt) );
753  }
754  }
755  }
756  }
757 }
758 
759 #endif
760