Again, bug fix in the Inspector support, on getSlot<> template.

The policy about how to create slots was not completly clear.
Now, only add *pointers* or *references* to class attributes,
never do a "copy by value". Reflect that change in SlotTemplate<>
various partial specializations.
  Hammer in your head that in C++ functions templates do not allow
for partial specialization. So write only *one* template for
::getSlot<>() (refdefinition simply got ignoreds, at least with gcc).

* Bug: In Slot, only one template for getSlot<> (see above).
    Adjust SlotTemplates<> to provides partial specialization only for:
    * "const Data&".
    * "Data*".
    * "const Data*".
    * "Data* const"
    * "Record*".
* Bug: In Instance::_getRecord(), suppress slot based on transient
    values "XCenter" & "YCenter".
* Bug: In CRL::ToolEngine::_getRecord(), suppress slot "Name" based
    on a transient value.
* Change: In ::getRecord(std::list<Elementt>*) (and variant), pass
    all elements to ::getSlot() as (const Element*).
This commit is contained in:
Jean-Paul Chaput 2021-01-08 12:43:47 +01:00
parent 678631d44f
commit 3b5a0f5bd2
8 changed files with 166 additions and 141 deletions

View File

@ -268,10 +268,10 @@ namespace CRL {
{
Record* record = Super::_getRecord();
if ( record ) {
record->add ( getSlot ( "Cell" , _cell ) );
record->add ( getSlot ( "Name" , getName() ) );
record->add ( getSlot ( "placementModificationFlag", _placementModificationFlag ) );
record->add ( getSlot ( "routingModificationFlag" , _routingModificationFlag ) );
record->add ( getSlot ( "_cell" , _cell ) );
//record->add ( getSlot ( "Name" , getName() ) );
record->add ( getSlot ( "_placementModificationFlag", _placementModificationFlag ) );
record->add ( getSlot ( "_routingModificationFlag" , _routingModificationFlag ) );
}
return record;
}

View File

@ -629,8 +629,8 @@ Record* Instance::_getRecord() const
record->add(getSlot("MasterCell", _masterCell));
record->add(getSlot("Transformation", &_transformation));
record->add(getSlot("PlacementStatus", &_placementStatus));
record->add(getSlot("XCenter", DbU::getValueString(getAbutmentBox().getXCenter())));
record->add(getSlot("YCenter", DbU::getValueString(getAbutmentBox().getYCenter())));
//record->add(getSlot("XCenter", DbU::getValueString(getAbutmentBox().getXCenter())));
//record->add(getSlot("YCenter", DbU::getValueString(getAbutmentBox().getYCenter())));
record->add(getSlot("Plugs", &_plugMap));
record->add(getSlot("SharedPathes", &_sharedPathMap));
}

View File

@ -32,9 +32,11 @@
// Needed for registering. May be deleted later.
#include "hurricane/Initializer.h"
#include "hurricane/DebugSession.h"
#include "hurricane/Error.h"
#include "hurricane/Warning.h"
#include "hurricane/Library.h"
#include "hurricane/Cell.h"
#include "hurricane/Entity.h"
//#include "hurricane/Library.h"
//#include "hurricane/Cell.h"
namespace Hurricane {

View File

@ -64,4 +64,7 @@ namespace Hurricane {
}
void* const Slot::getPData () const
{ return NULL; }
} // End of Hurricane namespace.

View File

@ -161,10 +161,7 @@ namespace Hurricane {
// Note 3: thoses templates manage all POD & STL types.
// Forward declaration of "getSlot<>()" template.
template<typename Data> inline Hurricane::Slot* getSlot ( std::string name, Data );
template<typename Data> inline Hurricane::Slot* getSlot ( std::string name, Data* );
// -------------------------------------------------------------------
@ -324,7 +321,10 @@ template<> inline std::string getString<std::string> ( std::string s )
template<typename Data> inline Hurricane::Record* getRecord ( Data data )
{ return NULL; }
{
//std::cerr << "::getRecord(Data) Data=" << Hurricane::demangle(typeid(data).name()) << std::endl;
return NULL;
}
// -------------------------------------------------------------------
@ -485,7 +485,7 @@ inline Hurricane::Record* getRecord ( std::vector<Element>* v )
unsigned n = 0;
typename std::vector<Element>::iterator iterator = v->begin();
while ( iterator != v->end() ) {
record->add ( getSlot<Element>(getString(n++), &(*iterator)) );
record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
++iterator;
}
}
@ -512,9 +512,9 @@ inline Hurricane::Record* getRecord ( std::vector<Element*>* v )
if ( !v->empty() ) {
record = new Hurricane::Record ( "std::vector<Element*>*" );
unsigned n = 0;
typename std::vector<Element>::iterator iterator = v->begin();
typename std::vector<Element*>::iterator iterator = v->begin();
while ( iterator != v->end() ) {
record->add ( getSlot<Element>(getString(n++), *iterator) );
record->add ( getSlot<Element*>(getString(n++), *iterator) );
++iterator;
}
}
@ -543,7 +543,7 @@ inline Hurricane::Record* getRecord ( const std::vector<Element>* v )
unsigned n = 0;
typename std::vector<Element>::const_iterator iterator = v->begin();
while ( iterator != v->end() ) {
record->add ( getSlot<const Element>(getString(n++), &(*iterator)) );
record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
++iterator;
}
}
@ -587,7 +587,7 @@ inline Hurricane::Record* getRecord ( const std::vector<Element*>* v )
template<typename Element>
inline std::string getString ( const std::list<Element>* l )
{
std::string name = "const std::list<Element>:";
std::string name = "const std::list<Element>*:";
return name + getString<size_t>(l->size());
}
@ -601,7 +601,7 @@ inline Hurricane::Record* getRecord ( const std::list<Element>* l )
unsigned n = 1;
typename std::list<Element>::const_iterator iterator = l->begin();
while ( iterator != l->end() ) {
record->add ( getSlot<const Element>(getString(n++), *iterator) );
record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
++iterator;
}
}
@ -612,7 +612,7 @@ inline Hurricane::Record* getRecord ( const std::list<Element>* l )
template<typename Element>
inline std::string getString ( std::list<Element>* l )
{
std::string name = "std::list<Element>:";
std::string name = "std::list<Element>*:";
return name + getString<size_t>(l->size());
}
@ -626,7 +626,7 @@ inline Hurricane::Record* getRecord ( std::list<Element>* l )
unsigned n = 1;
typename std::list<Element>::iterator iterator = l->begin();
while ( iterator != l->end() ) {
record->add ( getSlot<Element>(getString(n++), *iterator) );
record->add ( getSlot<const Element*>(getString(n++), &(*iterator)) );
++iterator;
}
}
@ -831,7 +831,7 @@ template< typename Element, typename Compare, typename Allocator >
inline Hurricane::Record* getRecord ( std::set<Element,Compare,Allocator>* s )
{
Hurricane::Record* record = NULL;
if ( !s->empty() ) {
if (not s->empty()) {
record = new Hurricane::Record ( "std::set<Element>" );
unsigned n = 1;
typename std::set<Element,Compare,Allocator>::iterator iterator = s->begin();

View File

@ -243,14 +243,14 @@ inline Hurricane::Record* getRecord<const Hurricane::Instance::PlacementStatus::
return record;
}
template<>
inline Hurricane::Record* getRecord<const Hurricane::Instance::PlacementStatus::Code>
( const Hurricane::Instance::PlacementStatus::Code object )
{
Hurricane::Record* record = new Hurricane::Record(getString(object));
record->add(getSlot("Code", (unsigned int)object));
return record;
}
// template<>
// inline Hurricane::Record* getRecord<const Hurricane::Instance::PlacementStatus::Code>
// ( const Hurricane::Instance::PlacementStatus::Code object )
// {
// Hurricane::Record* record = new Hurricane::Record(getString(object));
// record->add(getSlot("Code", (unsigned int)object));
// return record;
// }
INSPECTOR_P_SUPPORT(Hurricane::Instance);

View File

@ -29,13 +29,12 @@
// +-----------------------------------------------------------------+
#ifndef HURRICANE_SLOT_H
#define HURRICANE_SLOT_H
#ifndef HURRICANE_COMMONS_H
#error "Slot.h musn't be included alone, please uses Commons.h."
#endif
#ifndef HURRICANE_SLOT_H
#define HURRICANE_SLOT_H
namespace Hurricane {
@ -49,31 +48,32 @@ namespace Hurricane {
virtual ~Slot ();
// Accessors.
static size_t getAllocateds ();
const string& getName () const;
string getName () const;
virtual string getDataString () const = 0;
virtual Record* getDataRecord () const = 0;
virtual Slot* getClone () const = 0;
virtual void* const getPData () const;
protected:
// Internal: Static Attributes.
static size_t _allocateds;
// Internal: Attributes.
const string _name;
string _name;
protected:
// Internal: Constructors & Destructors.
Slot ( const string& name );
Slot ( string name );
};
// Inline Member Functions.
inline Slot::Slot ( const string& name ) : _name(name)
inline Slot::Slot ( string name ) : _name(name)
{
_allocateds++;
//cerr << "Slot::Slot() - " << _name << " " << hex << (void*)this << endl;
}
inline const string& Slot::getName () const { return _name; }
inline string Slot::getName () const { return _name; }
// -------------------------------------------------------------------
@ -82,15 +82,15 @@ namespace Hurricane {
template<typename Data>
class SlotTemplate : public Slot {
public:
SlotTemplate ( const string& name, Data data );
SlotTemplate ( string& name, Data data );
SlotTemplate ( string name, Data data );
virtual string getDataString () const;
virtual Record* getDataRecord () const;
virtual SlotTemplate<Data>*
getClone () const;
const Data& getData () const;
virtual void* const getPData () const;
protected:
Data _data;
const Data _data;
private:
SlotTemplate ( const SlotTemplate& );
SlotTemplate& operator= ( const SlotTemplate& );
@ -99,16 +99,12 @@ namespace Hurricane {
// Inline Member Functions.
template<typename Data>
SlotTemplate<Data>::SlotTemplate ( const string& name, Data data )
SlotTemplate<Data>::SlotTemplate ( string name, Data data )
: Slot(name), _data(data)
{
//std::cerr << " SlotTemplate<Data>::SlotTemplate() ( \"" << name << "\" )" << std::endl;
}
template<typename Data>
SlotTemplate<Data>::SlotTemplate ( string& name, Data data )
: Slot(name), _data(data) { }
template<typename Data>
string SlotTemplate<Data>::getDataString () const { return ::getString(_data); }
@ -126,22 +122,26 @@ namespace Hurricane {
return _data;
}
template<typename Data>
void* const SlotTemplate<Data>::getPData () const
{ return (void* const)( &_data ); }
// -------------------------------------------------------------------
// Class : "SlotTemplate<const Data>".
// Class : "SlotTemplate<const Data&>".
template<typename Data>
class SlotTemplate<const Data> : public Slot {
class SlotTemplate<const Data&> : public Slot {
public:
SlotTemplate ( const string& name, const Data data );
SlotTemplate ( string& name, const Data data );
SlotTemplate ( string name, const Data& data );
virtual string getDataString () const;
virtual Record* getDataRecord () const;
virtual SlotTemplate<const Data>*
virtual SlotTemplate<const Data&>*
getClone () const;
const Data& getData () const;
virtual void* const getPData () const;
protected:
const Data _data;
const Data& _data;
private:
SlotTemplate ( const SlotTemplate& );
SlotTemplate& operator= ( const SlotTemplate& );
@ -150,45 +150,45 @@ namespace Hurricane {
// Inline Member Functions.
template<typename Data>
SlotTemplate<const Data>::SlotTemplate ( const string& name, const Data data )
SlotTemplate<const Data&>::SlotTemplate ( string name, const Data& data )
: Slot(name), _data(data)
{
//std::cerr << "SlotTemplate<Data>::SlotTemplate(const Data) ( \"" << name << "\" )" << std::endl;
//std::cerr << " SlotTemplate<Data>::SlotTemplate(const Data&) ( \"" << name << "\" )" << std::endl;
}
template<typename Data>
SlotTemplate<const Data>::SlotTemplate ( string& name, const Data data )
: Slot(name), _data(data) { }
string SlotTemplate<const Data&>::getDataString () const { return ::getString(_data); }
template<typename Data>
string SlotTemplate<const Data>::getDataString () const { return ::getString(_data); }
Record* SlotTemplate<const Data&>::getDataRecord () const { return ::getRecord(_data); }
template<typename Data>
Record* SlotTemplate<const Data>::getDataRecord () const { return ::getRecord(_data); }
template<typename Data>
SlotTemplate<const Data>* SlotTemplate<const Data>::getClone () const
SlotTemplate<const Data&>* SlotTemplate<const Data&>::getClone () const
{ return new SlotTemplate(_name,_data); }
template<typename Data>
const Data& SlotTemplate<const Data>::getData () const
const Data& SlotTemplate<const Data&>::getData () const
{ return _data; }
template<typename Data>
void* const SlotTemplate<const Data&>::getPData () const
{ return (void* const)( &_data ); }
// -------------------------------------------------------------------
// Class : "SlotTemplate".
// Class : "SlotTemplate<Data*>".
template<typename Data>
class SlotTemplate<Data*> : public Slot {
public:
SlotTemplate ( const string& name, Data* data );
SlotTemplate ( string& name, Data* data );
SlotTemplate ( string name, Data* data );
virtual string getDataString () const;
virtual Record* getDataRecord () const;
virtual SlotTemplate<Data*>*
getClone () const;
Data* getData () const;
virtual void* const getPData () const;
private:
SlotTemplate ( const SlotTemplate& );
SlotTemplate& operator= ( const SlotTemplate& );
@ -199,16 +199,12 @@ namespace Hurricane {
// Inline Member Functions.
template<typename Data>
SlotTemplate<Data*>::SlotTemplate ( const string& name, Data* data )
SlotTemplate<Data*>::SlotTemplate ( string name, Data* data )
: Slot(name), _data(data)
{
//std::cerr << " SlotTemplate<Data*>::SlotTemplate(Data*) \"" << name << "\"" << std::endl;
}
template<typename Data>
SlotTemplate<Data*>::SlotTemplate ( string& name, Data* data )
: Slot(name), _data(data) {}
template<typename Data>
string SlotTemplate<Data*>::getDataString () const { return ::getString(_data); }
@ -230,21 +226,81 @@ namespace Hurricane {
return _data;
}
template<typename Data>
void* const SlotTemplate<Data*>::getPData () const
{ return (void* const)( _data ); }
// -------------------------------------------------------------------
// Class : "SlotTemplate".
// Class : "SlotTemplate<const Data*>".
template<typename Data>
class SlotTemplate<const Data*> : public Slot {
public:
SlotTemplate ( string name, const Data* data );
virtual string getDataString () const;
virtual Record* getDataRecord () const;
virtual SlotTemplate<const Data*>*
getClone () const;
Data* getData () const;
virtual void* const getPData () const;
private:
SlotTemplate ( const SlotTemplate& );
SlotTemplate& operator= ( const SlotTemplate& );
protected:
const Data* _data;
};
// Inline Member Functions.
template<typename Data>
SlotTemplate<const Data*>::SlotTemplate ( string name, const Data* data )
: Slot(name), _data(data)
{
//std::cerr << " SlotTemplate<const Data*>::SlotTemplate(const Data*) \"" << name << "\"" << std::endl;
}
template<typename Data>
string SlotTemplate<const Data*>::getDataString () const { return ::getString(_data); }
template<typename Data>
Record* SlotTemplate<const Data*>::getDataRecord () const
{
//std::cerr << "SlotTemplate<Data*>::getDataRecord()" << std::endl;
return ::getRecord(_data);
}
template<typename Data>
SlotTemplate<const Data*>* SlotTemplate<const Data*>::getClone () const
{ return new SlotTemplate(_name,_data); }
template<typename Data>
Data* SlotTemplate<const Data*>::getData () const
{
//std::cerr << "SlotTemplate<Data*>::getData()" << _data << std::endl;
return _data;
}
template<typename Data>
void* const SlotTemplate<const Data*>::getPData () const
{ return (void* const)( _data ); }
// -------------------------------------------------------------------
// Class : "SlotTemplate<Data* const>".
template<typename Data>
class SlotTemplate<Data* const> : public Slot {
public:
SlotTemplate ( const string& name, Data* const data );
SlotTemplate ( string& name, Data* const data );
SlotTemplate ( string name, Data* const data );
virtual string getDataString () const;
virtual Record* getDataRecord () const;
virtual SlotTemplate<Data* const>*
getClone () const;
Data* const getData () const;
virtual void* const getPData () const;
private:
SlotTemplate ( const SlotTemplate& );
SlotTemplate& operator= ( const SlotTemplate& );
@ -255,16 +311,12 @@ namespace Hurricane {
// Inline Member Functions.
template<typename Data>
SlotTemplate<Data* const>::SlotTemplate ( const string& name, Data* const data )
SlotTemplate<Data* const>::SlotTemplate ( string name, Data* const data )
: Slot(name), _data(data)
{
//std::cerr << "SlotTemplate<Data>::SlotTemplate(Data* const) ( \"" << name << "\" )" << std::endl;
}
template<typename Data>
SlotTemplate<Data* const>::SlotTemplate ( string& name, Data* const data )
: Slot(name), _data(data) {}
template<typename Data>
string SlotTemplate<Data* const>::getDataString () const { return ::getString(_data); }
@ -279,16 +331,19 @@ namespace Hurricane {
Data* const SlotTemplate<Data* const>::getData () const
{ return _data; }
template<typename Data>
void* const SlotTemplate<Data* const>::getPData () const
{ return (void* const)( _data ); }
// -------------------------------------------------------------------
// Class : "SlotTemplate".
// Class : "SlotTemplate<Record*>".
template<>
class SlotTemplate<Record*> : public Slot {
public:
inline SlotTemplate ( const string& name, Record* data );
inline SlotTemplate ( string& name, Record* data );
inline SlotTemplate ( string name, Record* data );
inline virtual string getDataString () const;
inline virtual Record* getDataRecord () const;
inline virtual SlotTemplate<Record*>*
@ -302,15 +357,12 @@ namespace Hurricane {
// Inline Member Functions.
inline SlotTemplate<Record*>::SlotTemplate ( const string& name, Record* data )
inline SlotTemplate<Record*>::SlotTemplate ( string name, Record* data )
: Slot(name), _data(data)
{
//std::cerr << "SlotTemplate<Data>::SlotTemplate(Record*) ( \"" << name << "\" )" << std::endl;
}
inline SlotTemplate<Record*>::SlotTemplate ( string& name, Record* data )
: Slot(name), _data(data) {}
inline string SlotTemplate<Record*>::getDataString () const { return _name; }
inline Record* SlotTemplate<Record*>::getDataRecord () const { return _data; }
@ -324,34 +376,10 @@ namespace Hurricane {
template<typename Data>
inline Hurricane::Slot* getSlot( std::string name, Data d )
{
//std::cerr << "getSlot<string&,Data>( \"" << name << "\" )" << std::endl;
// std::cerr << "getSlot<const string&,Data>( \"" << name << "\" )"
// << " Data=" << Hurricane::demangle(typeid(d).name()) << std::endl;
return new Hurricane::SlotTemplate<Data>( name, d );
}
template<typename Data>
inline Hurricane::Slot* getSlot( std::string name, Data* d )
{
//std::cerr << "getSlot<string&,Data*>( \"" << name << "\" )" << std::endl;
return new Hurricane::SlotTemplate<Data*> ( name, d );
}
// template<typename Data>
// inline Hurricane::Slot* getSlot( const std::string& name, Data d )
// {
// //std::cerr << "getSlot<const string&,Data>( \"" << name << "\" )" << std::endl;
// //std::cerr << " Data = " << typeid(d).name() << std::endl;
// return new Hurricane::SlotTemplate<Data> ( name, d );
// }
// template<typename Data>
// inline Hurricane::Slot* getSlot( const std::string& name, Data* d )
// {
// //std::cerr << "getSlot<const string&,Data*>( \"" << name << "\" )" << std::endl;
// //std::cerr << " Data = " << typeid(d).name() << std::endl;
// return new Hurricane::SlotTemplate<Data*> ( name, d );
// }
#endif // HURRICANE_SLOT_H

View File

@ -16,7 +16,6 @@
#include <QFont>
#include <QApplication>
#include "hurricane/Name.h"
#include "hurricane/viewer/Graphics.h"
#include "hurricane/viewer/RecordModel.h"
@ -44,7 +43,6 @@ namespace Hurricane {
bool RecordModel::setSlot ( Slot* slot, Record* record, size_t depth )
{
//cerr << " Slot change" << endl;
emit layoutAboutToBeChanged ();
vector< pair<QVariant,QVariant> >().swap( _cache );
@ -57,21 +55,17 @@ namespace Hurricane {
_slot = NULL;
_record = NULL;
_depth = depth;
if ( slot == NULL ) {
//cerr << " NULL Slot" << endl;
if (not slot) {
emit layoutChanged ();
return false;
}
// Now supplied by argument.
if ( record == NULL ) {
if (not record) {
record = slot->getDataRecord ();
//cerr << " New record build" << endl;
if ( record == NULL ) {
//cerr << " Slot " << slot->getDataString() << " has NULL Record" << endl;
delete slot;
emit layoutChanged ();
return false;
@ -79,20 +73,18 @@ namespace Hurricane {
}
//cerr << " New Slot [" << depth << "] " << slot->getDataString() << endl;
_slot = slot;
_record = record;
_depth = depth;
Record::SlotVector& slotVector = _record->_getSlotVector();
Record::SlotVector::iterator islot = slotVector.begin();
for ( ; islot != slotVector.end() ; islot++ ) {
_cache.push_back ( make_pair(QVariant(getString((*islot)->getName()).c_str())
,QVariant((*islot)->getDataString().c_str())) );
for ( Slot* child : _record->_getSlotVector() ) {
//cerr << "ADD slot to _cache " << child->getPData() << endl;
//cerr << " name= \"" << child->getName() << "\"" << endl;
//cerr << " data= \"" << child->getDataString() << "\"" << endl;
_cache.push_back ( make_pair(QVariant(child->getName().c_str())
,QVariant(child->getDataString().c_str())) );
}
emit layoutChanged ();
return true;
}