@@ -143,25 +143,51 @@ void Config::SetItem(an<ConfigItem> item) {
143143 set_modified ();
144144}
145145
146- static const ResourceType kConfigResourceType = {
146+ const ResourceType ConfigComponentBase:: kConfigResourceType = {
147147 " config" ,
148148 " " ,
149149 " .yaml" ,
150150};
151151
152- ConfigComponent::ConfigComponent ( )
152+ ConfigComponentBase::ConfigComponentBase ( const ResourceType& resource_type )
153153 : resource_resolver_(
154- Service::instance ().CreateResourceResolver(kConfigResourceType )) {
154+ Service::instance ().CreateResourceResolver(resource_type )) {
155155}
156156
157- ConfigComponent ::~ConfigComponent () {
157+ ConfigComponentBase ::~ConfigComponentBase () {
158158}
159159
160- Config* ConfigComponent ::Create (const string& file_name) {
160+ Config* ConfigComponentBase ::Create (const string& file_name) {
161161 return new Config (GetConfigData (file_name));
162162}
163163
164- void ConfigComponent::InstallPlugin (ConfigCompilerPlugin* plugin) {
164+ an<ConfigData> ConfigComponentBase::GetConfigData (const string& file_name) {
165+ auto config_id = resource_resolver_->ToResourceId (file_name);
166+ // keep a weak reference to the shared config data in the component
167+ weak<ConfigData>& wp (cache_[config_id]);
168+ if (wp.expired ()) { // create a new copy and load it
169+ auto data = LoadConfig (config_id);
170+ wp = data;
171+ return data;
172+ }
173+ // obtain the shared copy
174+ return wp.lock ();
175+ }
176+
177+ an<ConfigData> ConfigLoader::LoadConfig (ResourceResolver* resource_resolver,
178+ const string& config_id) {
179+ auto data = New<ConfigData>();
180+ data->LoadFromFile (
181+ resource_resolver->ResolvePath (config_id).string (), nullptr );
182+ data->set_auto_save (auto_save_);
183+ return data;
184+ }
185+
186+ ConfigBuilder::ConfigBuilder () {}
187+
188+ ConfigBuilder::~ConfigBuilder () {}
189+
190+ void ConfigBuilder::InstallPlugin (ConfigCompilerPlugin* plugin) {
165191 plugins_.push_back (the<ConfigCompilerPlugin>(plugin));
166192}
167193
@@ -182,7 +208,6 @@ struct MultiplePlugins : ConfigCompilerPlugin {
182208 return ReviewedByAll (&ConfigCompilerPlugin::ReviewLinkOutput,
183209 compiler, resource);
184210 }
185-
186211 typedef bool (ConfigCompilerPlugin::*Reviewer)(ConfigCompiler* compiler,
187212 an<ConfigResource> resource);
188213 bool ReviewedByAll (Reviewer reviewer,
@@ -201,22 +226,15 @@ bool MultiplePlugins<Container>::ReviewedByAll(Reviewer reviewer,
201226 return true ;
202227}
203228
204- an<ConfigData> ConfigComponent::GetConfigData (const string& file_name) {
205- auto config_id = resource_resolver_->ToResourceId (file_name);
206- // keep a weak reference to the shared config data in the component
207- weak<ConfigData>& wp (cache_[config_id]);
208- if (wp.expired ()) { // create a new copy and load it
209- MultiplePlugins<decltype (plugins_)> multiple_plugins (plugins_);
210- ConfigCompiler compiler (resource_resolver_.get (), &multiple_plugins);
211- auto resource = compiler.Compile (file_name);
212- if (resource->loaded && !compiler.Link (resource)) {
213- LOG (ERROR) << " error loading config from: " << file_name;
214- }
215- wp = resource->data ;
216- return resource->data ;
229+ an<ConfigData> ConfigBuilder::LoadConfig (ResourceResolver* resource_resolver,
230+ const string& config_id) {
231+ MultiplePlugins<decltype (plugins_)> multiple_plugins (plugins_);
232+ ConfigCompiler compiler (resource_resolver, &multiple_plugins);
233+ auto resource = compiler.Compile (config_id);
234+ if (resource->loaded && !compiler.Link (resource)) {
235+ LOG (ERROR) << " error building config: " << config_id;
217236 }
218- // obtain the shared copy
219- return wp.lock ();
237+ return resource->data ;
220238}
221239
222240} // namespace rime
0 commit comments