OpenASIP  2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
HDB::HDBRegistry Class Reference

#include <HDBRegistry.hh>

Collaboration diagram for HDB::HDBRegistry:
Collaboration graph

Public Member Functions

virtual ~HDBRegistry ()
 
CachedHDBManagerhdb (const std::string fileName)
 
void loadFromSearchPaths ()
 
void addHDB (CachedHDBManager *hdbManager)
 
bool hasHDB (const std::string &hdbFile)
 
int hdbCount ()
 
CachedHDBManagerhdb (unsigned int index)
 
std::string hdbPath (unsigned int index)
 
int hdbErrorCount ()
 
std::string hdbErrorMessage (unsigned int index)
 

Static Public Member Functions

static HDBRegistryinstance ()
 

Private Member Functions

 HDBRegistry ()
 HDB registry must be created with instance() method. More...
 
void removeDeadHDBPaths ()
 Deletes nonexistent HDB paths from registry. More...
 

Private Attributes

std::map< const std::string, CachedHDBManager * > registry_
 all opened HDBs are stored in this map More...
 
std::vector< std::string > errorMessages_
 errors found during loading HDBs are strored in this vector More...
 

Static Private Attributes

static HDBRegistryinstance_ = NULL
 Unique instance of the class. More...
 

Detailed Description

Registry for multiple HDBs.

Definition at line 46 of file HDBRegistry.hh.

Constructor & Destructor Documentation

◆ ~HDBRegistry()

HDB::HDBRegistry::~HDBRegistry ( )
virtual

Destructor.

Definition at line 52 of file HDBRegistry.cc.

References AssocTools::deleteAllValues(), and registry_.

Here is the call graph for this function:

◆ HDBRegistry()

HDB::HDBRegistry::HDBRegistry ( )
private

HDB registry must be created with instance() method.

Constructor.

Definition at line 46 of file HDBRegistry.cc.

46  {
47 }

Referenced by instance().

Member Function Documentation

◆ addHDB()

void HDB::HDBRegistry::addHDB ( CachedHDBManager hdbManager)

Adds HDBManager in to the registry.

Takes responsibility of deleting the given HDBManager.

Parameters
hdbThe HDBManager to be added in to the registry.

Definition at line 100 of file HDBRegistry.cc.

100  {
101 
103  registry_, FileSystem::absolutePathOf(hdbManager->fileName()))) {
104 
105  delete hdbManager;
106  hdbManager = NULL;
107  return;
108  }
109  registry_[FileSystem::absolutePathOf(hdbManager->fileName())] = hdbManager;
110 }

References FileSystem::absolutePathOf(), AssocTools::containsKey(), HDB::HDBManager::fileName(), and registry_.

Referenced by HDB::CachedHDBManager::instance().

Here is the call graph for this function:

◆ hasHDB()

bool HDB::HDBRegistry::hasHDB ( const std::string &  hdbFile)

Returns true if the registry contains a HDBManager of the given HDB file.

Parameters
hdbFileThe HDB file managed by the HDBManager.
Returns
True if the registry contains a HDBManager of the given HDB file.

Definition at line 119 of file HDBRegistry.cc.

119  {
120 
123  return true;
124  } else {
125  return false;
126  }
127 }

References FileSystem::absolutePathOf(), AssocTools::containsKey(), and registry_.

Referenced by HDB::CachedHDBManager::instance().

Here is the call graph for this function:

◆ hdb() [1/2]

CachedHDBManager & HDB::HDBRegistry::hdb ( const std::string  fileName)

Returns the HDB at given path.

In case the HDB is not found in registry, tries to open it.

Parameters
fileNameFile name of the HDB.
Returns
The HDB associated with the file name.
Exceptions
ExceptionIn case there was a problem while opening the HDB.

Definition at line 80 of file HDBRegistry.cc.

80  {
83  return *registry_[FileSystem::absolutePathOf(fileName)];
84  }
85  CachedHDBManager* manager = &CachedHDBManager::instance(
86  FileSystem::absolutePathOf(fileName));
87 
88  registry_[FileSystem::absolutePathOf(fileName)] = manager;
89  return *manager;
90 }

References FileSystem::absolutePathOf(), AssocTools::containsKey(), HDB::CachedHDBManager::instance(), and registry_.

Referenced by DefaultICDecoderEstimator::delayOfBus(), DefaultICDecoderEstimator::delayOfSocket(), DefaultICDecoderEstimator::estimateICArea(), DefaultICDecoderEstimator::estimateICDelayOfPath(), DefaultICDecoderEstimator::estimateICEnergy(), ComponentImplementationSelector::fuArchsByOpSetWithMinLatency(), CostEstimator::Estimator::fuCostFunctionPluginOfImplementation(), ComponentImplementationSelector::fuImplementations(), CostEstimator::Estimator::functionUnitArea(), CostEstimator::Estimator::functionUnitEnergy(), CostEstimator::Estimator::functionUnitMaximumComputationDelay(), CostEstimator::Estimator::functionUnitPortReadDelay(), CostEstimator::Estimator::functionUnitPortWriteDelay(), ProGeScriptGenerator::getBlockOrder(), HDB::CachedHDBManager::instance(), ComponentImplementationSelector::iuImplementations(), PlatformIntegrator::loadFUExternalPorts(), main(), CostEstimator::Estimator::registerFileArea(), CostEstimator::Estimator::registerFileEnergy(), CostEstimator::Estimator::registerFileMaximumComputationDelay(), CostEstimator::Estimator::registerFilePortReadDelay(), CostEstimator::Estimator::registerFilePortWriteDelay(), CostEstimator::Estimator::rfCostFunctionPluginOfImplementation(), ComponentImplementationSelector::rfImplementations(), ComponentImplementationSelector::selectComponents(), HDBEditorMainFrame::setHDB(), ImplementationSelector::setupSelector(), AddFUFromHDBDialog::TransferDataToWindow(), and AddRFFromHDBDialog::TransferDataToWindow().

Here is the call graph for this function:

◆ hdb() [2/2]

CachedHDBManager & HDB::HDBRegistry::hdb ( unsigned int  index)

Returns the HDB from given index.

Returns
The HDB from the given index.
Exceptions
OutOfRangeIs thrown if index is bigger than the HDB count.

Definition at line 192 of file HDBRegistry.cc.

192  {
193  if (index > (registry_.size() - 1)) {
194  throw OutOfRange(__FILE__, __LINE__,
195  "HDBRegistry::hdb(unsigned int)");
196  }
197  std::map<const std::string, CachedHDBManager*>::const_iterator
198  mapIterator = registry_.begin();
199  for (unsigned int counter = 0; mapIterator != registry_.end();
200  mapIterator++) {
201  if (counter == index) {
202  break;
203  } else {
204  counter++;
205  }
206  }
207  return *(*mapIterator).second;
208 }

References registry_.

◆ hdbCount()

int HDB::HDBRegistry::hdbCount ( )

◆ hdbErrorCount()

int HDB::HDBRegistry::hdbErrorCount ( )

Returns the number of error messages created during HDB loading.

Returns
The number of error messages created during HDB loading.

Definition at line 238 of file HDBRegistry.cc.

238  {
239 
240  return errorMessages_.size();
241 }

References errorMessages_.

Referenced by AddFUFromHDBDialog::TransferDataToWindow(), and AddRFFromHDBDialog::TransferDataToWindow().

◆ hdbErrorMessage()

std::string HDB::HDBRegistry::hdbErrorMessage ( unsigned int  index)

Returns the error message from given index.

Returns
The error message in given index.
Exceptions
OutOfRangeIs thrown if index is bigger than the HDB error count.

Definition at line 251 of file HDBRegistry.cc.

251  {
252  if (index > (errorMessages_.size() - 1)) {
253  throw OutOfRange(__FILE__, __LINE__,
254  "HDBRegistry::hdbErrorMessage(unsigned int)");
255  }
256  return errorMessages_[index];
257 }

References errorMessages_.

Referenced by AddFUFromHDBDialog::TransferDataToWindow(), and AddRFFromHDBDialog::TransferDataToWindow().

◆ hdbPath()

std::string HDB::HDBRegistry::hdbPath ( unsigned int  index)

Returns the full path of the HDB with given index.

Returns
The HDB file path.
Exceptions
OutOfRangeIs thrown if index is out of range.

Definition at line 217 of file HDBRegistry.cc.

217  {
218  if (index > (registry_.size() - 1)) {
219  throw OutOfRange(__FILE__, __LINE__,
220  "HDBRegistry::hdb(unsigned int)");
221  }
222  std::map<const std::string, CachedHDBManager*>::const_iterator iter =
223  registry_.begin();
224 
225  for (unsigned c = 0; iter != registry_.end(); iter++) {
226  if (c == index) return (*iter).first;
227  c++;
228  }
229  assert(false);
230 }

References assert, and registry_.

Referenced by AutoSelectImplementationsDialog::AutoSelectImplementationsDialog(), and BlockImplementationDialog::BlockImplementationDialog().

◆ instance()

HDBRegistry & HDB::HDBRegistry::instance ( )
static

Creates and returns an instance of HDB registry.

Returns
An instance of HDB registry.

Definition at line 62 of file HDBRegistry.cc.

62  {
63 
64  if (instance_ == NULL) {
65  instance_ = new HDBRegistry();
66  }
67  return *instance_;
68 }

References HDBRegistry(), and instance_.

Referenced by CostEstimator::Estimator::estimateSocketToSocketDelayOfPath(), ComponentImplementationSelector::fuArchsByOpSetWithMinLatency(), CostEstimator::Estimator::fuCostFunctionPluginOfImplementation(), ComponentImplementationSelector::fuImplementations(), CostEstimator::Estimator::functionUnitArea(), CostEstimator::Estimator::functionUnitEnergy(), CostEstimator::Estimator::functionUnitMaximumComputationDelay(), CostEstimator::Estimator::functionUnitPortReadDelay(), CostEstimator::Estimator::functionUnitPortWriteDelay(), ProGeScriptGenerator::getBlockOrder(), CostEstimator::Estimator::icArea(), CostEstimator::Estimator::icEnergy(), HDB::CachedHDBManager::instance(), ComponentImplementationSelector::iuImplementations(), PlatformIntegrator::loadFUExternalPorts(), main(), CostEstimator::Estimator::registerFileArea(), CostEstimator::Estimator::registerFileEnergy(), CostEstimator::Estimator::registerFileMaximumComputationDelay(), CostEstimator::Estimator::registerFilePortReadDelay(), CostEstimator::Estimator::registerFilePortWriteDelay(), CostEstimator::Estimator::rfCostFunctionPluginOfImplementation(), ComponentImplementationSelector::rfImplementations(), ComponentImplementationSelector::selectComponents(), HDBEditorMainFrame::setHDB(), and HDBTester::~HDBTester().

Here is the call graph for this function:

◆ loadFromSearchPaths()

void HDB::HDBRegistry::loadFromSearchPaths ( )

Definition at line 146 of file HDBRegistry.cc.

146  {
147 
148  // check every HDB path exists, and if doesn't, remove from registry
150 
151  const std::vector<std::string> hdbPaths = Environment::hdbPaths();
152  std::vector<std::string>::const_iterator hdbIter = hdbPaths.begin();
153  for(; hdbIter != hdbPaths.end(); hdbIter++) {
154  if (!FileSystem::fileExists(*hdbIter) ||
155  !FileSystem::fileIsDirectory(*hdbIter) ||
156  !FileSystem::fileIsReadable(*hdbIter)) {
157  // Directory doesn't exist or can't be read.
158  continue;
159  }
160  std::vector<std::string> dir =
162  std::vector<std::string>::const_iterator dirIter = dir.begin();
163  for (; dirIter != dir.end(); dirIter++) {
164  std::string file = (*dirIter);
165  if (file.rfind(".hdb", file.size()) != std::string::npos &&
166  file.rfind(".hdb", file.size()) == (file.size() - 4)) {
167  if (!AssocTools::containsKey(registry_, file)) {
168  try {
169  CachedHDBManager* manager =
172 
173  registry_[FileSystem::absolutePathOf(file)] = manager;
174  } catch (IOException& e) {
175  std::string errorMessage = "Error in '" + file +
176  "': " + e.errorMessage() + ".";
177  errorMessages_.push_back(errorMessage);
178  }
179  }
180  }
181  }
182  }
183 }

References FileSystem::absolutePathOf(), AssocTools::containsKey(), FileSystem::directoryContents(), Exception::errorMessage(), errorMessages_, FileSystem::fileExists(), FileSystem::fileIsDirectory(), FileSystem::fileIsReadable(), Environment::hdbPaths(), HDB::CachedHDBManager::instance(), registry_, and removeDeadHDBPaths().

Referenced by AutoSelectImplementationsDialog::AutoSelectImplementationsDialog(), BlockImplementationDialog::BlockImplementationDialog(), FrequencySweepExplorer::openHDBs(), ImplementationSelector::setupSelector(), AddRFFromHDBDialog::TransferDataToWindow(), and AddFUFromHDBDialog::TransferDataToWindow().

Here is the call graph for this function:

◆ removeDeadHDBPaths()

void HDB::HDBRegistry::removeDeadHDBPaths ( )
private

Deletes nonexistent HDB paths from registry.

Removes nonexistent HDB files from registry.

Definition at line 263 of file HDBRegistry.cc.

263  {
264 
265  std::map<const std::string, CachedHDBManager*>::iterator it;
266  for (it = registry_.begin(); it != registry_.end(); ) {
267  if (!FileSystem::fileExists(it->first)) {
268  registry_.erase(it->first);
269  ++it;
270  } else {
271  ++it;
272  }
273  }
274 }

References FileSystem::fileExists(), and registry_.

Referenced by loadFromSearchPaths().

Here is the call graph for this function:

Member Data Documentation

◆ errorMessages_

std::vector<std::string> HDB::HDBRegistry::errorMessages_
private

errors found during loading HDBs are strored in this vector

Definition at line 69 of file HDBRegistry.hh.

Referenced by hdbErrorCount(), hdbErrorMessage(), and loadFromSearchPaths().

◆ instance_

HDBRegistry * HDB::HDBRegistry::instance_ = NULL
staticprivate

Unique instance of the class.

Definition at line 71 of file HDBRegistry.hh.

Referenced by instance().

◆ registry_

std::map<const std::string, CachedHDBManager*> HDB::HDBRegistry::registry_
private

all opened HDBs are stored in this map

Definition at line 67 of file HDBRegistry.hh.

Referenced by addHDB(), hasHDB(), hdb(), hdbCount(), hdbPath(), loadFromSearchPaths(), removeDeadHDBPaths(), and ~HDBRegistry().


The documentation for this class was generated from the following files:
HDB::HDBRegistry::errorMessages_
std::vector< std::string > errorMessages_
errors found during loading HDBs are strored in this vector
Definition: HDBRegistry.hh:69
AssocTools::containsKey
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
OutOfRange
Definition: Exception.hh:320
HDB::HDBRegistry::HDBRegistry
HDBRegistry()
HDB registry must be created with instance() method.
Definition: HDBRegistry.cc:46
FileSystem::absolutePathOf
static std::string absolutePathOf(const std::string &pathName)
Definition: FileSystem.cc:303
assert
#define assert(condition)
Definition: Application.hh:86
FileSystem::fileIsDirectory
static bool fileIsDirectory(const std::string fileName)
Environment::hdbPaths
static std::vector< std::string > hdbPaths(bool libraryPathsOnly=false)
Definition: Environment.cc:683
HDB::HDBRegistry::instance_
static HDBRegistry * instance_
Unique instance of the class.
Definition: HDBRegistry.hh:71
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
HDB::HDBRegistry::registry_
std::map< const std::string, CachedHDBManager * > registry_
all opened HDBs are stored in this map
Definition: HDBRegistry.hh:67
FileSystem::fileExists
static bool fileExists(const std::string fileName)
IOException
Definition: Exception.hh:130
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)
AssocTools::deleteAllValues
static void deleteAllValues(ContainerType &aMap)
FileSystem::directoryContents
static std::vector< std::string > directoryContents(const std::string &directory, const bool absolutePaths=true)
Definition: FileSystem.cc:600
HDB::CachedHDBManager::instance
static CachedHDBManager & instance(const std::string &hdbFile)
Definition: CachedHDBManager.cc:89
HDB::HDBRegistry::removeDeadHDBPaths
void removeDeadHDBPaths()
Deletes nonexistent HDB paths from registry.
Definition: HDBRegistry.cc:263