All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DriverSet.cpp
Go to the documentation of this file.
1 /*
2  * DriverSet.cpp
3  *
4  * This file is part of the HausmiSEP project
5  *
6  * Copyright (C) 2012, 2013 Marco Alvarado (malvcr@gmail.com)
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <HSEP/DirTool.h>
23 #include <HSEP/ErrorCode.h>
24 #include <HSEP/DriverSet.h>
25 #include <cstring>
26 
27 namespace HSEP {
28 
29  bool BaseDriverSet::load(string& pPathRef,string& pPrefixRef) {
30 
31  bool vResult = false;
32  size_t vPrefixLen = pPrefixRef.length();
33 
34  unload();
35 
36  StringArray vFileNames;
37 
38  if (EC::OK==DirTool::traverse(vFileNames,pPathRef,pPrefixRef)) {
39 
40  vFileNames.forEach([&](string* pItem) {
41 
42  size_t vSize = pItem->size();
43 
44  // Don't even try to load something that is not a standard
45  // library or whose name is not big enough to be a valid one.
46  //
47  if ((vSize > (LIBRARY_SUFFIX_LEN+vPrefixLen)) &&
48  (pItem->substr(vSize-LIBRARY_SUFFIX_LEN,LIBRARY_SUFFIX_LEN)==LIBRARY_SUFFIX)) {
49 
50  string vFilePath = pPathRef;
51  vFilePath.append("/");
52  vFilePath.append(*pItem);
53 
54  string vTypeNameStr;
55 
56  vTypeNameStr = pItem->substr(vPrefixLen,vSize-vPrefixLen-LIBRARY_SUFFIX_LEN);
57 
58  // This function is a template one defined in the header file
59  _addLibrary(vTypeNameStr.c_str(),vFilePath,aFactoryName);
60  }
61 
62  });
63 
64  } //if (EC::OK==DirTool::traverse(vFileNames,pPath,pPrefix)) {
65 
66  return vResult;
67 
68  } // BaseDriverSet::load
69 
70 } // HSEP namespace