tomwalters@84
|
1 // Copyright 2010, Thomas Walters
|
tomwalters@84
|
2 //
|
tomwalters@84
|
3 // AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@84
|
4 // http://www.acousticscale.org/AIMC
|
tomwalters@84
|
5 //
|
tomwalters@84
|
6 // Licensed under the Apache License, Version 2.0 (the "License");
|
tomwalters@84
|
7 // you may not use this file except in compliance with the License.
|
tomwalters@84
|
8 // You may obtain a copy of the License at
|
tomwalters@84
|
9 //
|
tomwalters@84
|
10 // http://www.apache.org/licenses/LICENSE-2.0
|
tomwalters@84
|
11 //
|
tomwalters@84
|
12 // Unless required by applicable law or agreed to in writing, software
|
tomwalters@84
|
13 // distributed under the License is distributed on an "AS IS" BASIS,
|
tomwalters@84
|
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
tomwalters@84
|
15 // See the License for the specific language governing permissions and
|
tomwalters@84
|
16 // limitations under the License.
|
tomwalters@84
|
17
|
tomwalters@84
|
18 /*! \file
|
tomwalters@84
|
19 * \brief Parse a configuration file to generate a tree of modules.
|
tomwalters@84
|
20 */
|
tomwalters@84
|
21
|
tomwalters@84
|
22 /*! \author: Thomas Walters <tom@acousticscale.org>
|
tomwalters@84
|
23 * \date 2010/08/08
|
tomwalters@84
|
24 * \version \$Id: $
|
tomwalters@84
|
25 */
|
tomwalters@84
|
26
|
tomwalters@114
|
27 #include "Support/ModuleTree.h"
|
tomwalters@114
|
28
|
tomwalters@114
|
29 #include "Support/ModuleFactory.h"
|
tomwalters@114
|
30
|
tomwalters@84
|
31 namespace aimc {
|
tomwalters@114
|
32 LoadConfigFile(const string &filename) {
|
tomwalters@114
|
33 parameters_.Load(filename.c_str());
|
tomwalters@114
|
34 return ConstructTree();
|
tomwalters@114
|
35 }
|
tomwalters@114
|
36
|
tomwalters@114
|
37 LoadConfigText(const string &config) {
|
tomwalters@114
|
38 parameters_.Parse(config.c_str());
|
tomwalters@114
|
39 return ConstructTree();
|
tomwalters@114
|
40 }
|
tomwalters@114
|
41
|
tomwalters@114
|
42 ConstructTree() {
|
tomwalters@114
|
43 // Make two passes over the configuration file.
|
tomwalters@114
|
44 // The first pass creates all the named modules with their parameters.
|
tomwalters@114
|
45 bool done = false;
|
tomwalters@114
|
46 bool error = false;
|
tomwalters@114
|
47 string module;
|
tomwalters@114
|
48 int module_number = 1;
|
tomwalters@114
|
49 while (!done) {
|
tomwalters@114
|
50 module = sprintf("module%d", module_number);
|
tomwalters@114
|
51 if (parameters_.IsSet(module + ".name") {
|
tomwalters@114
|
52 string module_name =
|
tomwalters@114
|
53 string module_id =
|
tomwalters@114
|
54 string module_params =
|
tomwalters@114
|
55 modules_[]
|
tomwalters@114
|
56 } else {
|
tomwalters@114
|
57 done = true;
|
tomwalters@114
|
58 }
|
tomwalters@114
|
59 ++module_number;
|
tomwalters@114
|
60 }
|
tomwalters@114
|
61 // The second pass connects up all the modules into a tree.
|
tomwalters@84
|
62
|
tomwalters@114
|
63 return error;
|
tomwalters@114
|
64 }
|
tomwalters@84
|
65 } // namespace aimc |