34 #include <boost/algorithm/string.hpp>
35 #include <boost/filesystem.hpp>
41 std::vector<ElementConfigMap> &outElemMapVector, std::vector<ConfigBitMap> &outConfigMapVector) {
44 boost::filesystem::directory_iterator eFiles;
45 boost::filesystem::directory_iterator pFiles(libPath);
46 while(pFiles != eFiles) {
49 if(pFiles->path().extension() ==
".cbit") {
51 std::ifstream libBitFile(pFiles->path().string().c_str(), std::ios::binary);
52 if(!libBitFile.good()) {
53 std::cerr <<
"ERROR: Could not open micro-bitstream file " << pFiles->path().string() << std::endl;
58 int32_t numSetBits, bitAddr;
59 libBitFile.read((
char *) &numSetBits, 4);
60 std::cout << pFiles->path().filename() <<
" opened. Bit count " << numSetBits << std::endl;
61 std::vector<uint32_t> bitAddresses;
62 for(
int i = 0; i < numSetBits && !libBitFile.eof(); i++) {
63 libBitFile.read((
char *) &bitAddr, 4);
64 bitAddresses.push_back(bitAddr);
69 std::string fileName(filePath.replace_extension().filename());
71 std::vector<std::string> splitVector;
72 boost::algorithm::split(splitVector, fileName, boost::algorithm::is_any_of(
kNameSeparator));
73 for(std::vector<std::string>::const_iterator splitIter = splitVector.begin(); splitIter
74 != splitVector.end(); splitIter++) {
75 std::cout <<
" " << *splitIter << std::endl;
86 if(outTileMap.find(tileType) == outTileMap.end()) {
88 outElemMapVector.push_back(elementConfigMap);
89 outTileMap[tileType] = outElemMapVector.back();
93 if(outTileMap[tileType].find(element) == outTileMap[tileType].end()) {
95 outConfigMapVector.push_back(configBitmap);
96 outTileMap[tileType][element] = outConfigMapVector.back();
100 outTileMap[tileType][element][config] = bitAddresses;
108 int main(
int argc,
char **argv) {
112 std::cout <<
"Pass correct parameters. Usage: " << argv[0]
113 <<
" <folder of compressed bit files" << std::endl;
119 if(!boost::filesystem::exists(libPath)) {
120 std::cout <<
"The folder " << libPath.string().c_str() <<
" does not exist" << std::endl;
125 std::vector<ConfigBitMap> configMapVector;
126 std::vector<ElementConfigMap> elementMapVector;
132 std::ofstream dbFile(dbFilePath.string().c_str(), std::ofstream::binary);
134 std::cout <<
"Could not open file " << dbFilePath.string() <<
" to write" << std::endl;
139 PopulateMaps(libPath, tileMap, elementMapVector, configMapVector);
141 std::cout <<
"Opened file " << dbFilePath.string() <<
" to store library database" << std::endl;
142 dbFile.write(
"<<<<BITLIBDB>>>>", 16);
145 dataSize = tileMap.size();
146 dbFile.write((
char *) (&dataSize),
sizeof(dataSize));
151 TiletypeElementMap::const_iterator pTiletypes = tileMap.begin();
152 TiletypeElementMap::const_iterator eTiletypes = tileMap.end();
153 while(pTiletypes != eTiletypes) {
156 dataSize = pTiletypes->first.size();
157 dbFile.write((
const char *) &dataSize,
sizeof(dataSize));
158 dbFile.write((
const char *) pTiletypes->first.c_str(), pTiletypes->first.size());
159 dataSize = pTiletypes->second.size();
160 dbFile.write((
const char*) &dataSize,
sizeof(dataSize));
161 std::cout <<
"Tile type " << pTiletypes->first <<
" has " << pTiletypes->second.size()
162 <<
" elements." << std::endl;
165 ElementConfigMap::const_iterator pElements = pTiletypes->second.begin();
166 ElementConfigMap::const_iterator eElements = pTiletypes->second.end();
167 while(pElements != eElements) {
170 dataSize = pElements->first.size();
171 dbFile.write((
const char *) &dataSize,
sizeof(dataSize));
172 dbFile.write((
const char *) pElements->first.c_str(), pElements->first.size());
173 dataSize = pElements->second.size();
174 dbFile.write((
const char *) &dataSize,
sizeof(dataSize));
179 ConfigBitMap::const_iterator pConfigs = pElements->second.begin();
180 ConfigBitMap::const_iterator eConfigs = pElements->second.end();
181 while(pConfigs != eConfigs) {
183 dataSize = pConfigs->first.size();
184 dbFile.write((
const char *) &dataSize,
sizeof(dataSize));
185 dbFile.write(pConfigs->first.c_str(), pConfigs->first.size());
186 dataSize = pConfigs->second.size();
187 dbFile.write((
const char *) &dataSize,
sizeof(dataSize));
190 for(std::vector<uint32_t>::const_iterator iter = pConfigs->second.begin(); iter
191 != pConfigs->second.end(); iter++) {
192 dbFile.write((
char *) &*iter,
sizeof(uint32_t));
void PopulateMaps(boost::filesystem::path libPath, TiletypeElementMap &outTileMap, std::vector< ElementConfigMap > &outElemMapVector, std::vector< ConfigBitMap > &outConfigMapVector)
std::map< const std::string, std::vector< uint32_t > > ConfigBitMap
boost::filesystem::path path
const std::string kNameSeparator
std::map< const std::string, ElementConfigMap > TiletypeElementMap
const std::string kFamily
int main(int argc, char **argv)
std::map< const std::string, ConfigBitMap > ElementConfigMap