40 #ifndef _objectsettings_cpp
41 #define _objectsettings_cpp
43 #include "objectsettings.h"
44 #include "stringtool.h"
76 this->
SubSets.push_back( NewSubSet );
84 this->
SubSets.push_back( ToBeAdded );
91 if( Name == (*it)->GetName() ) {
92 if(0 == Which)
return (*it);
101 return this->
SubSets.at(Index);
108 if( ToBeRemoved == (*it) ) {
121 if( Name == (*it)->GetName() ) {
135 (*it)->ParentSetOrGroup = NULL;
145 {
return this->
SubSets.begin(); }
148 {
return this->
SubSets.begin(); }
151 {
return this->
SubSets.end(); }
154 {
return this->
SubSets.end(); }
161 ParentSetOrGroup(NULL)
178 this->
Settings.insert( std::pair<String,String>(SettingName,StringValue) );
185 if( SetIt != this->
Settings.end() )
return (*SetIt).second;
260 {
return this->
File; }
279 if( Name == (*SaveIt)->GetName() )
289 if( Group == (*SaveIt) ) {
333 SettingsDoc.
Load(SettingsStream);
343 if( !RootNode.
Empty() ) {
345 if( !RootNode.
Empty() ) {
356 for( SettingGroupVector::iterator It = RetVec->begin() ; It != RetVec->end() ; ++It )
388 if( !CurrAttrib.
Empty() )
404 CurrAttrib.
SetValue( (*SetIt).second );
429 this->
SettingGroups.insert( std::pair<String,ObjectSettingGroup*>(Name,NewGroup) );
436 if( SetIt != this->
SettingGroups.end() )
return (*SetIt).second;
444 delete (*SetIt).second;
458 delete (*SetIt).second;
469 this->
SettingFiles.insert( std::pair<String,ObjectSettingFile*>(FileName,NewFile) );
476 if( SettingFileIt != this->
SettingFiles.end() )
return (*SettingFileIt).second;
501 ToDestroy = (*SettingFileIt).second;
510 if( FileName.empty() )
514 if( SettingFileIt != this->
SettingFiles.end() ) GroupFile = (*SettingFileIt).second;
518 this->
SettingFiles.insert( std::pair<String,ObjectSettingFile*>(FileName,GroupFile) );
521 GroupFile->AddGroup(Group);
526 if( FileName.empty() )
530 if( SettingFileIt != this->SettingFiles.end() ) (*SettingFileIt).second->RemoveGroup(Group);
537 void ObjectSettingsHandler::SetSettingsFilePath(
const String& Path)
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;
547 this->SettingsFilePath = Path;
550 if( this->AutoGenPath )
551 ResourceManager::GetSingletonPtr()->CreateDirectoryPath(this->SettingsFilePath);
554 const String& ObjectSettingsHandler::GetSettingsFilePath()
const
556 return this->SettingsFilePath;
559 void ObjectSettingsHandler::SetCurrentSettingsSaveFile(
const String& FileName)
561 this->CurrentSettingsSaveFile = FileName;
564 ConstString& ObjectSettingsHandler::GetCurrentSettingsSaveFile()
const
566 return this->CurrentSettingsSaveFile;
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 +
"\".");
578 return this->LoadSettingsFromFile(FileName,FilePath);
583 return this->LoadSettingsFromFile(FileName,Path);
588 if( this->SettingsFilePath.empty() ) {
589 MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,
"Attempting to use a preset path that hasn't been set.");
591 return this->LoadSettingsFromFile(FileName,SettingsFilePath);
600 XML::Node CurrGroupNode = (*CurrGroupIt);
601 String SettingGroupName = CurrGroupNode.
Name();
603 if(
"Current" != SettingGroupName ) {
604 this->SettingGroups.insert( std::pair<String,ObjectSettingGroup*>(SettingGroupName,NewGroup) );
605 RetVec->push_back(NewGroup);
607 if(!SetAfter) SetAfter = NewGroup;
608 else { MEZZ_EXCEPTION(Exception::II_DUPLICATE_IDENTITY_EXCEPTION,
"Multiple \"Current\" setting groups detected while loading settings."); }
615 this->LoadSettingSetFromXML( CurrSetNode, NewSet );
619 this->ApplySettingGroupImpl(SetAfter);
628 void ObjectSettingsHandler::SetAutoGenPath(Boolean Enable)
629 { this->AutoGenPath = Enable; }
631 Boolean ObjectSettingsHandler::GetAutoGenPath()
const
632 {
return this->AutoGenPath; }
634 void ObjectSettingsHandler::SetAutoGenFiles(Boolean Enable)
635 { this->AutoGenFiles = Enable; }
637 Boolean ObjectSettingsHandler::GetAutoGenFiles()
const
638 {
return this->AutoGenFiles; }
640 void ObjectSettingsHandler::SaveAllSettings()
642 if( this->SettingsFilePath.empty() ) {
643 MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,
"Attempting to use a preset path that hasn't been set.");
647 for(
SettingFilesIterator SettingFileIt = this->SettingFiles.begin() ; SettingFileIt != this->SettingFiles.end() ; ++SettingFileIt )
650 Boolean IsCurrentSettingsFile = ( CurrentSettingsSaveFile == CurrFile->
GetFileName() );
651 if( CurrFile->
GetNeedsSave() || IsCurrentSettingsFile ) {
652 if( IsCurrentSettingsFile )
653 GroupNames.push_back(
"Current" );
656 GroupNames.push_back( (*SetGroupIt)->GetName() );
658 this->SaveSettingsToFile(GroupNames,(*SettingFileIt).second->GetFileName(),SettingsFilePath);
666 void ObjectSettingsHandler::SaveSettingsByFile(
const String& FileName,
const String& Path)
669 if( this->CurrentSettingsSaveFile == FileName )
670 GroupNames.push_back(
"Current" );
673 if( SetFileIt == this->SettingFiles.end() ) {
674 MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,
"Setting file \"" + FileName +
"\" was not found when attempting to save.");
679 GroupNames.push_back( (*SetGroupIt)->GetName() );
681 this->SaveSettingsToFile(GroupNames,FileName,Path);
682 (*SetFileIt).second->SetNeedsSave(
false);
685 void ObjectSettingsHandler::SaveSettingsByFile(
const String& FileName)
687 if( this->SettingsFilePath.empty() ) {
688 MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,
"Attempting to use a preset path that hasn't been set.");
692 if( this->CurrentSettingsSaveFile == FileName )
693 GroupNames.push_back(
"Current" );
696 if( SetFileIt == this->SettingFiles.end() ) {
697 MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,
"Setting file \"" + FileName +
"\" was not found when attempting to save.");
702 GroupNames.push_back( (*SetGroupIt)->GetName() );
704 this->SaveSettingsToFile(GroupNames,FileName,SettingsFilePath);
705 (*SetFileIt).second->SetNeedsSave(
false);
710 this->SaveSettingsToFile(GroupNames,FileName,Path);
715 if( this->SettingsFilePath.empty() ) {
716 MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,
"Attempting to use a preset path that hasn't been set.");
719 this->SaveSettingsToFile(GroupNames,FileName,SettingsFilePath);
722 void ObjectSettingsHandler::SaveSettingsToXML(
XML::Node& RootSettings, Boolean SaveCurrent)
727 GroupNames.push_back(
"Current" );
729 for(
SettingGroupIterator GroupNameIt = this->SettingGroups.begin() ; GroupNameIt != this->SettingGroups.end() ; ++GroupNameIt )
731 GroupNames.push_back( (*GroupNameIt).first );
733 this->SaveSettingsToXML(GroupNames,RootSettings);
738 for( StringVector::iterator StrIt = GroupNames.begin() ; StrIt != GroupNames.end() ; ++StrIt )
740 if(
"Current" == (*StrIt) ) {
741 this->AppendCurrentSettings(RootSettings);
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.");
752 this->SaveSettingSetToXML( SetNode, (*SubSetIt) );