Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PUBLIC - Constructor
- Identification::Identification( const std::string typeName_ = std::string("Identification"), const bool active_ = true):
- _typeNameID(this->pullTypeNameID(typeName_)),
- _instanceID(this->pullInstanceID()),
- _active(active_),
- _reference(this)
- {};
- //Destructor
- Identification::~Identification(){
- this->pushInstanceID();
- };
- //Const Access
- const bool& Identification::active() const {
- return _active;
- }
- const void* const Identification::reference() const {
- return _reference;
- };
- const std::string& Identification::typeName() const {
- return _typeNames[_typeNameID];
- };
- const unsigned int& Identification::instanceID() const {
- return _instanceID;
- };
- const unsigned int& Identification::typeNameID() const {
- return _typeNameID;
- }
- //Debug and Metrics
- std::string Identification::display() {//not fleshed
- std::stringstream out( std::stringstream::in | std::stringstream::out | std::stringstream::trunc );
- out.seekp(0, std::ios::beg);
- out << "Identification :\n\n";
- out << "::_typeNames.size() : " << _typeNames.size() << "\n";
- for (unsigned int k=0; k < _typeNames.size(); k++){
- out << "::_typeNames[ " << k << ", " <<_typeNames[k] << " ] : " << _typeNames[k] <<" ("<<Identification::instancesCount()[k]<<")\n";
- }
- out << "\n::_nextInstanceIDs.size() : " << _nextInstanceIDs.size() << "\n";
- for (unsigned int k=0; k < _nextInstanceIDs.size(); k++){
- out << "::_nextInstanceIDs[ " << k <<", " <<_typeNames[k] << " ] : " << _nextInstanceIDs[k] << " \n";
- };
- out << "\n::_freeInstanceIDs.size() : " << _freeInstanceIDs.size() << "\n";
- for (unsigned int j=0; j <_freeInstanceIDs.size(); j++){
- out << "::_freeInstanceIDs[ " << j<< " ].size() : " << _freeInstanceIDs[j].size() << "\n";
- if (!_freeInstanceIDs[j].empty()){
- std::queue<unsigned int> _freeInstanceIDsTemp= _freeInstanceIDs[j];
- out << "\t::_freeInstanceIDs[ " << j << " ][ " << 0 << ":"<<(_freeInstanceIDsTemp.size()-1)<<" ] : " ;
- while (!_freeInstanceIDsTemp.empty()){
- out << _freeInstanceIDsTemp.front() << " ";
- _freeInstanceIDsTemp.pop();
- }
- out << "\n";
- }
- }
- unsigned int length = out.tellp();
- out.seekg(0,std::ios::beg);
- char* buffer = new char[length];
- out.read(buffer,length);
- std::string _buffer(buffer);
- delete [ ] buffer;
- _buffer += "\n\0";
- return _buffer;
- };
- unsigned int Identification::typeNamesCount() {
- return _typeNames.size();
- }
- std::vector<unsigned int> Identification::freeIDsCount(){
- std::vector<unsigned int> freeIDsCount_;
- for (unsigned int k=0; k <Identification::typeNamesCount(); k++){
- freeIDsCount_.push_back(_freeInstanceIDs[k].size());
- }
- return freeIDsCount_;
- }
- std::vector<unsigned int> Identification::instancesCount(){
- std::vector<unsigned int> instancesCount_;
- for (unsigned int k=0; k < Identification::typeNamesCount(); k++){
- instancesCount_.push_back( Identification::nextInstanceIDs()[k] - Identification::freeIDsCount()[k]);
- }
- return instancesCount_;
- }
- int Identification::findTypeNameID(const std::string& typeName_){
- for(unsigned int k=0; k < _typeNames.size(); k++) {
- if (_typeNames[k] == typeName_) {
- return k;
- };
- };
- return -1;
- }
- //Use
- void* const Identification::reference() {
- return _reference;
- };
- //PROTECTED - Activation
- void Identification::activate(){
- _active = true;
- _instanceID = pullInstanceID();
- };
- void Identification::deactivate(){
- _active = false;
- this->pushInstanceID();
- };
- //Mod Stat Access
- std::vector<std::string>& Identification::typeNames() {
- return _typeNames;
- }
- std::vector<unsigned int>& Identification::nextInstanceIDs() {
- return _nextInstanceIDs;
- }
- std::vector<std::queue<unsigned int> >& Identification::freeInstanceIDs() {
- return _freeInstanceIDs;
- }
- //PRIVATE - Internal Management
- void Identification::pushInstanceID() {
- _freeInstanceIDs[_typeNameID].push(_instanceID);
- };
- const unsigned int Identification::pullInstanceID() {
- if (_freeInstanceIDs[_typeNameID].empty() ) {
- return _nextInstanceIDs[_typeNameID]++;
- };
- unsigned int freeInstanceID_ = _freeInstanceIDs[_typeNameID].front();
- _freeInstanceIDs[_typeNameID].pop();
- return freeInstanceID_;
- };
- const unsigned int Identification::pullTypeNameID(const std::string& typeName_) {
- for (unsigned int k=0; k< _typeNames.size(); k++){
- if (_typeNames[k] == typeName_){
- return k;
- }
- }
- _typeNames.push_back(typeName_);
- _nextInstanceIDs.push_back(0);
- _freeInstanceIDs.push_back(std::queue<unsigned int>());
- return (_typeNames.size()-(unsigned int)(1));
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement