/** *----------------------------------------------------------------------------- * Title : Rogue as a library base class * ---------------------------------------------------------------------------- * File : LibraryBase.h * ---------------------------------------------------------------------------- * Description: * Base class for creating a Rogue shared library * ---------------------------------------------------------------------------- * This file is part of the rogue software platform. It is subject to * the license terms in the LICENSE.txt file found in the top-level directory * of this distribution and at: * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. * No part of the rogue software platform, including this file, may be * copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE.txt file. * ---------------------------------------------------------------------------- **/ #ifndef __ROGUE_LIBRARY_BASE_H__ #define __ROGUE_LIBRARY_BASE_H__ #include "rogue/Directives.h" #include #include #include #include #include #include #include #include #include "rogue/Logging.h" #include "rogue/interfaces/memory/Block.h" #include "rogue/interfaces/memory/Slave.h" #include "rogue/interfaces/memory/Variable.h" #include "rogue/interfaces/stream/Master.h" #include "rogue/interfaces/stream/Slave.h" namespace rogue { //! LibraryBase class LibraryBase { // Logger std::shared_ptr log_; //! Map of variables std::map> variables_; //! Map of blocks by block name std::map> blocks_; //! Map of memory interfaces std::map> memSlaves_; //! Map of missing memory interfaces std::set memSlavesMissing_; public: LibraryBase(); ~LibraryBase(); //! Add slave memory interface void addMemory(std::string name, std::shared_ptr slave); // Parse memory map void parseMemMap(std::string map); void parseMemMap(const char* filePath, char delim = '\n'); void parseMemMap(std::istream& fStream, char delim); static std::shared_ptr create(); //! Read all variables void readAll(); //! Get variable by name std::shared_ptr getVariable(const std::string& name); //! Get a const reference to the map of variables const std::map>& getVariableList(); //! Get block by name std::shared_ptr getBlock(const std::string& name); //! Get a map of blocks const std::map> getBlockList(); private: //! Create a variable void createVariable( std::map& data, std::map>>& blockVars); //! Helper function to get string from fields std::string getFieldString(std::map fields, std::string name); //! Helper function to get uint64_t from fields uint64_t getFieldUInt64(std::map fields, std::string name); //! Helper function to get uint32_t from fields uint32_t getFieldUInt32(std::map fields, std::string name, bool def = false); //! Helper function to get bool from fields bool getFieldBool(std::map fields, std::string name); //! Helper function to get double from fields double getFieldDouble(std::map fields, std::string name); //! Helper function to get uint32_t vector from fields std::vector getFieldVectorUInt32(std::map fields, std::string name); //! Dump the current state of the registers in the system void dumpRegisterStatus(std::string filename, bool read, bool includeStatus = false); }; typedef std::shared_ptr LibraryBasePtr; } // namespace rogue #endif