1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program 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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdgeorgesconvert.h"
18 #include "mold_loader.h"
20 #include "mold_elt_define.h"
21 #include "mold_elt_type.h"
22 #include "mold_elt_define_list.h"
23 #include "mold_elt_type_list.h"
24 #include "georges_loader.h"
26 namespace NLOLDGEORGES
29 //////////////////////////////////////////////////////////////////////
30 // Construction/Destruction
31 //////////////////////////////////////////////////////////////////////
33 CMoldLoader::CMoldLoader()
37 CMoldLoader::~CMoldLoader()
42 void CMoldLoader::Clear()
44 for( std::vector
< CMoldElt
* >::iterator it
= vpme
.begin(); it
!= vpme
.end(); ++it
)
51 void CMoldLoader::SetLoader( CLoader
* const _pl
)
57 CMoldElt
* CMoldLoader::LoadMold( const CStringEx _sxfilename
)
59 CStringEx sxfn
= _sxfilename
;
65 bool blst
= ( sxfn
.find( "list<" ) != -1 );
68 unsigned int ipos
= sxfn
.find( ">" );
71 sxfn
.mid( 5, ipos
-5 );
75 int ipos
= sxfn
.reverse_find('.');
78 CStringEx sxfileextension
= sxfn
.get_right( sxfn
.length()-ipos
-1 );
80 // Get only the filename
81 ipos
= sxfn
.reverse_find('\\');
83 sxfn
= sxfn
.get_right (sxfn
.length()-ipos
-1);
87 CStringEx sxfullname
= pl
->WhereIsDfnTyp( sxfn
);
89 throw NLMISC::Exception ("Unable to find " + sxfn
);
91 sxfullname
.make_lower();
92 std::map
< CStringEx
, CMoldElt
* >::iterator it
;
95 /*for (it = mmold.begin(); it != mmold.end(); ++it)
97 CMoldElt *pME = it->second;
98 CStringEx sTmp = it->first + " Name:" + pME->GetName() + " formula:" + pME->GetFormula();
99 nlwarning (sTmp.c_str());
103 it
= mmold
.find( sxfullname
);
104 if( it
!= mmold
.end() )
107 if( sxfileextension
== "dfn" )
108 pme
= new CMoldEltDefineList( pl
, dynamic_cast< CMoldEltDefine
* >( it
->second
) );
109 else if( sxfileextension
== "typ" )
110 pme
= new CMoldEltTypeList( pl
, dynamic_cast< CMoldEltType
* >( it
->second
) );
113 pme
->SetName( it
->second
->GetName() );
114 vpme
.push_back( pme
);
118 return( it
->second
);
121 if( sxfileextension
== "dfn" )
123 pme
= new CMoldEltDefine( pl
);
124 vpme
.push_back( pme
);
127 pme
= new CMoldEltDefineList( pl
, dynamic_cast< CMoldEltDefine
* >( pme
) );
128 vpme
.push_back( pme
);
131 else if( sxfileextension
== "typ" )
133 pme
= new CMoldEltType( pl
);
134 vpme
.push_back( pme
);
137 pme
= new CMoldEltTypeList( pl
, dynamic_cast< CMoldEltType
* >( pme
) );
138 vpme
.push_back( pme
);
144 pme
->SetName( sxfn
);
145 pme
->Load( sxfullname
);
146 mmold
.insert( std::make_pair( sxfullname
, pme
->GetMold() ) );
150 CMoldElt
* CMoldLoader::LoadMold( const CStringEx _sxfilename
, const CStringEx _sxdate
)
155 CMoldElt* CMoldLoader::Find( const CStringEx _sxfullname )
157 std::map< CStringEx, CMoldElt* >::iterator it = mmold.find( _sxfullname );
158 if( it != mmold.end() )
159 return( it->second );