<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Well, at first, I didn't want to bother people with the details. But now, it seems that it is needed.<div><br></div><div>The definition of the class and the implementation are below. Here is a git repo on which one can find the whole project : <a href="git://github.com/ggutierrez/cprelmaster.git">git://github.com/ggutierrez/cprelmaster.git</a></div><div>(the class is defined in rel/grelation.hh)</div><div><br></div><div>In my experience with SWIG and CFFI, I've never had that kind of problem. At some point, the implementation is using a library named cudd (<a href="http://vlsi.colorado.edu/~fabio/CUDD/">http://vlsi.colorado.edu/~fabio/CUDD/</a>). Maybe the problem comes from there, I really don't know.</div><div><br></div><div>Thank you you for any help, it is highly appreciated. </div><div><br></div><div>Sascha</div><div><br></div><div><div>class GRelation {</div><div> private:</div><div> friend class GRelationIter;</div><div> typedef boost::shared_ptr<VarImpl::RelationImpl> Impl;</div><div> Impl pimpl_; ///> Relation storage</div><div> /// Avoid default construction</div><div> GRelation(void);</div><div> /// Constructor taking an implementation</div><div> explicit GRelation(Impl impl);</div><div> public:</div><div> /// \name Constructors, destructors and assignement</div><div> //@{</div><div> /// Constructor for an empty relation of arity \a a</div><div> explicit GRelation(int a);</div><div> /// Copy constructor</div><div> GRelation(const GRelation& r);</div><div> /// Assignment</div><div> GRelation& operator=(GRelation& right);</div><div> void become(const GRelation& other);</div><div><br></div><div> /// Destructor</div><div> ~GRelation(void);</div><div> /// Constructs the relation \f$R=\mathcal{U}_{a}\f$</div><div> static GRelation create_full(int a);</div><div> //@}</div><div> /// \name Modification operations</div><div> //@{</div><div> /**</div><div> * \brief Adds tuple \a t to the relation. If \f$ t \in this \f$ the relation</div><div> * remains unchanged.</div><div> */</div><div> void add(const Tuple& t);</div><div> /**</div><div> * \brief Adds the tuples contained in \a s to the relation.</div><div> */</div><div> void add(const std::vector<Tuple>& s);</div><div> /**</div><div> * \brief Union of relations: \f$ this = this \cup r \f$.</div><div> */</div><div> void unionAssign(const GRelation& r);</div><div> /**</div><div> * \brief Difference of relations: \f$ this = this \setminus r \f$.</div><div> */</div><div> void differenceAssign(const GRelation& r);</div><div> //@}</div><div> /// \name Set operations</div><div> //@{</div><div> /// Computes \f$ this \setminus r \f$</div><div> GRelation difference(const GRelation& r) const;</div><div> /// Computes \f$ this \cap r \f$</div><div> GRelation intersect(const GRelation& r) const;</div><div> /// Computes \f$ this \cup r \f$</div><div> GRelation Union(const GRelation& r) const;</div><div> /// Computes \f$ \overline{this}\f$</div><div> GRelation complement(void) const;</div><div> //@}</div><div> /// \name Column permutation</div><div> //@{</div><div> /**</div><div> * \brief Computes the permutation of \a this according to \a desc.</div><div> *</div><div> * \warning The permutation descriptor has to be valid for the relation. If it</div><div> * is not then a InvalidPermDescriptor exception is thrown.</div><div> */</div><div> GRelation permute(const std::vector<std::pair<int,int>>& desc) const;</div><div> /**</div><div> * \brief Computes the permutation of \a this according to \a desc.</div><div> *</div><div> * \warning The permutation descriptor has to be valid for the relation. If it</div><div> * is not then a InvalidPermDescriptor exception is thrown.</div><div> */</div><div> GRelation permute(const PermDescriptor& desc) const;</div><div> /**</div><div> * \brief Computes the relation resulting by shifting all the columns in \a r</div><div> * \a n possitions to the right.</div><div> *</div><div> * The first \a n columns of \a r does not appear in the final relation.</div><div> */</div><div> GRelation shiftRight(int n) const;</div><div> //@}</div><div> /// \name Cross product</div><div> //@{</div><div> /**</div><div> * \brief Computes \f$ \mathcal{U}_n \times this\f$.</div><div> */</div><div> GRelation timesULeft(int n) const;</div><div> /**</div><div> * \brief Computes \f$ this \times \mathcal{U}_n \f$.</div><div> */</div><div> GRelation timesURight(int n) const;</div><div> /**</div><div> * \brief Computes \f$ this \times r \f$</div><div> */</div><div> GRelation times(const GRelation& r) const;</div><div> //@}</div><div> /// \name Relational algebra operations</div><div> //@{</div><div> /**</div><div> * \brief Returns: \f$ \mathit{this}\;\bowtie_{j}\; r \f$.</div><div> *</div><div> * This is, the result of joining the two relations on the \a j right most</div><div> * columns of \a this and the \a j left most columns of \a r.</div><div> */</div><div> GRelation join(int j,const GRelation& r) const;</div><div> /**</div><div> * \brief Returns: \f$ \mathit{this}_{\smile_{f}}r \f$.</div><div> *</div><div> * \todo documentation</div><div> */</div><div> GRelation follow(int f,const GRelation& r) const; </div><div> /**</div><div> * \brief Returns: \f$ \Pi_{p} this \f$.</div><div> *</div><div> * This is, the projection of \a this on the \a p rightmost columns.</div><div> *</div><div> * \warning Throws an exception InvalidProjection if \a p is not a valid column</div><div> * in the relation.</div><div> */</div><div> GRelation project(int p) const;</div><div> //@}</div><div> /// \name Quantification</div><div> //@{</div><div> /**</div><div> * \brief Returns the relation resulting from existencially quantifying on</div><div> * column \a c</div><div> *</div><div> * \param c a column: \f$ 0 \leq c < \text{arity}(\text{this})\f$</div><div> */</div><div> GRelation exists(int c) const;</div><div> /**</div><div> * \brief Returns the relation resulting from uniquely quantifying on column</div><div> * \a c</div><div> *</div><div> * \param c a column: \f$ 0 \leq c < \text{arity}(\text{this})\f$</div><div> */</div><div> GRelation unique(int c) const;</div><div> /**</div><div> * \brief Returns the relation resulting from uniquely quantifying on all the</div><div> * columns in \a c.</div><div> *</div><div> * \param c a vector of columns: \f$ \forall_{i \in</div><div> * \{0,\ldots,\text{size}(c)-1\}}: 0 \leq c[i] <</div><div> * \text{arity}(\text{this})\f$</div><div> */</div><div> GRelation unique(const std::vector<int>& c) const;</div><div> /**</div><div> * \brief Returns the relation resulting from universaly quantifying on column</div><div> * \a c</div><div> *</div><div> * \param c a column: \f$ 0 \leq c < \text{arity}(\text{this})\f$</div><div> */</div><div> GRelation forall(int c) const;</div><div> //@}</div><div><br></div><div> /**</div><div> * \brief Computes the relation resulting by shifting all the columns in \a r</div><div> * \a n possitions to the left.</div><div> *</div><div> * The new columns in the resulting relation are existentially quantified.</div><div> */</div><div> //GRelation shiftLeft(int n) const;</div><div> /// Returns the relation \f$ this \times r \f$</div><div> //@}</div><div> /// \name Test operations</div><div> //@{</div><div> /// Tests \f$ this \subseteq r \f$</div><div> bool subsetEq(const GRelation& r) const;</div><div> /// Tests \f$ this \supset r \f$</div><div> bool superset(const GRelation& r) const;</div><div> /// Tests \f$ this \cap r = \emptyset \f$</div><div> bool disjoint(const GRelation& r) const;</div><div> /// Tests whether this represents the same relation as \a r</div><div> bool eq(const GRelation& r) const;</div><div> /// Tests whther the relation is empty</div><div> bool empty(void) const;</div><div> /// Tests whther the relation represents the universe</div><div> bool universe(void) const;</div><div> //@}</div><div> /// \name Relation information</div><div> //@{</div><div> /// Returns the arity (i.e. number of columns) of the relation</div><div> int arity(void) const;</div><div> /// Returns the cardinality (i.e. number of tuples) of the relation</div><div> double cardinality(void) const;</div><div> //@}</div><div> /// \name Constant relations</div><div> //@{</div><div> /// Creates the binary relation \f$ R = \{(x,y) : x = y \} \f$</div><div> //static GRelation equalXY(void);</div><div> //@}</div><div> /// \name Content access</div><div> //@{</div><div> /**</div><div> * \brief Returns one tuple represented by the relation.</div><div> *</div><div> * The only guarantee on the returned tuple is that it belongs to</div><div> * the relation.</div><div> */</div><div> Tuple pickOneTuple(void) const;</div><div> //@} </div><div> /// \name Output</div><div> //{@</div><div> void print(std::ostream& os) const;</div><div> //@}</div><div> };</div></div><div><br></div><div><br></div><div><div> GRelation::GRelation(Impl impl)</div><div> : pimpl_(impl) {}</div><div><br></div><div> GRelation::GRelation(int a)</div><div> : pimpl_(Impl(new RelationImpl(a)))</div><div> {}</div><div><br></div><div> GRelation::GRelation(const GRelation &r)</div><div> : pimpl_(new RelationImpl(*(r.pimpl_))) { }</div><div><br></div><div> GRelation& GRelation::operator =(GRelation& right) {</div><div> pimpl_.swap(right.pimpl_);</div><div> return *this;</div><div> }</div><div><br></div><div> void GRelation::become(const GRelation& other) {</div><div> pimpl_ = Impl(new RelationImpl(*(other.pimpl_)));</div><div> }</div><div><br></div><div> GRelation::~GRelation(void) {}</div><div><br></div><div> GRelation GRelation::create_full(int a) {</div><div> RelationImpl full = RelationImpl::create_full(a);</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(full))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> /*</div><div> * Modification</div><div> */ </div><div> void GRelation::add(const Tuple &t) {</div><div> pimpl_->add(t);</div><div> }</div><div><br></div><div> void GRelation::add(const std::vector<Tuple>& s) {</div><div> std::for_each(s.begin(), s.end(),</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> [=](const Tuple& t) { pimpl_->add(t); });</div><div> }</div><div><br></div><div> void GRelation::unionAssign(const GRelation &r) {</div><div> pimpl_->add(*(r.pimpl_));</div><div> }</div><div><br></div><div> void GRelation::differenceAssign(const GRelation &r) {</div><div> pimpl_->remove(*(r.pimpl_));</div><div> }</div><div><br></div><div> /*</div><div> * Set operations</div><div> */ </div><div> GRelation GRelation::difference(const GRelation &r) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(VarImpl::difference(*pimpl_,*(r.pimpl_))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::intersect(const GRelation &r) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(VarImpl::intersect(*pimpl_,*(r.pimpl_))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::Union(const GRelation &r) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(VarImpl::Union(*pimpl_,*(r.pimpl_))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::complement(void) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(VarImpl::complement(*pimpl_)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> /*</div><div> * Column permutation</div><div> */ </div><div> GRelation GRelation::permute(const std::vector<std::pair<int,int>>& desc) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->permute(desc)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::permute(const PermDescriptor& desc) const {</div><div> typedef boost::error_info<struct tag_perm_descriptor,std::string></div><div> perm_descriptor;</div><div> </div><div> if (!desc.valid(arity()))</div><div> throw InvalidPermDescriptor()</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><< errno_code(errno)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><< perm_descriptor("Invalid permutation description used at: GRelation::permute");</div><div> </div><div> return permute(desc.getPerm());</div><div> }</div><div> </div><div> GRelation GRelation::shiftRight(int n) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->shiftRight(n)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> /*</div><div> * Cross product</div><div> */ </div><div> GRelation GRelation::timesULeft(int n) const {</div><div> return</div><div> GRelation(Impl(new RelationImpl(pimpl_->timesULeft(n))));</div><div> }</div><div><br></div><div><br></div><div> GRelation GRelation::timesURight(int n) const {</div><div> return</div><div> GRelation(Impl(new RelationImpl(pimpl_->timesURight(n))));</div><div> }</div><div> </div><div> GRelation GRelation::times(const GRelation& r) const {</div><div> return join(0,r);</div><div> }</div><div> </div><div> /*</div><div> * Relational algebra</div><div> */ </div><div> GRelation GRelation::join(int j,const GRelation& r) const {</div><div> typedef boost::error_info<struct tag_invalid_join,std::string></div><div> invalid_join;</div><div><br></div><div> if (arity() < j || r.arity() < j)</div><div> throw InvalidJoin()</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> << errno_code(errno)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> << invalid_join("There are not enough columns for the join");</div><div><br></div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->join(j, *(r.pimpl_))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::follow(int f,const GRelation& right) const {</div><div> /// \todo handle arity errors with exceptions</div><div><br></div><div> // if (arity() < j || r.arity() < j)</div><div> // throw InvalidJoin()</div><div> // << errno_code(errno)</div><div> // << invalid_join("There are not enough columns for the join");</div><div><br></div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->follow(f, *(right.pimpl_))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::project(int p) const {</div><div> typedef boost::error_info<struct tag_projection,std::string></div><div> projection;</div><div><br></div><div> if(p <= 0 || p > arity()) {</div><div> throw InvalidProjection()</div><div> << errno_code(errno)</div><div> << projection("Invalid columns to project on");</div><div> }</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->project(p)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> /*</div><div> * Quantification</div><div> */ </div><div> GRelation GRelation::exists(int c) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->exists(c)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::unique(int c) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->unique(c)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::unique(const std::vector<int>& c) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->unique(c)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div> GRelation GRelation::forall(int c) const {</div><div> return</div><div> GRelation(</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Impl(new RelationImpl(pimpl_->forall(c)))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>);</div><div> }</div><div><br></div><div><br></div><div> /*</div><div> * Test operations</div><div> */ </div><div> bool GRelation::subsetEq(const GRelation& r) const {</div><div> return VarImpl::subsetEq(*pimpl_,*r.pimpl_);</div><div> }</div><div><br></div><div> bool GRelation::superset(const GRelation& r) const {</div><div> return VarImpl::superset(*pimpl_,*r.pimpl_);</div><div> }</div><div><br></div><div> bool GRelation::disjoint(const GRelation& r) const {</div><div> return VarImpl::disjoint(*pimpl_,*r.pimpl_);</div><div> }</div><div><br></div><div> bool GRelation::eq(const GRelation& r) const {</div><div> return *pimpl_ == *(r.pimpl_);</div><div> }</div><div><br></div><div> bool GRelation::empty(void) const {</div><div> return pimpl_->empty();</div><div> }</div><div><br></div><div> bool GRelation::universe(void) const {</div><div> return pimpl_->universe();</div><div> }</div><div><br></div><div> /*</div><div> * Relation information</div><div> */ </div><div> int GRelation::arity(void) const {</div><div> return pimpl_->arity();</div><div> }</div><div><br></div><div> double GRelation::cardinality(void) const {</div><div> return pimpl_->cardinality();</div><div> }</div><div><br></div><div> /*</div><div> * Content access</div><div> */ </div><div> Tuple GRelation::pickOneTuple(void) const {</div><div> /// \todo throw an exception</div><div> assert(!empty() && "Relation is empty, nothing to return");</div><div> return</div><div> pimpl_->pickOneTuple();</div><div> }</div><div><br></div><div> /*</div><div> * Relation output</div><div> */ </div><div> void GRelation::print(std::ostream& os) const {</div><div> pimpl_->print(os);</div><div> }</div><div><br></div><div> std::ostream& operator<< (std::ostream& os, const GRelation& r) {</div><div> r.print(os);</div><div> return os;</div><div> }</div></div><div><br></div><div><br><div><div>Le 25 nov. 2011 à 18:25, Frank Goenninger a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Am 25.11.2011 um 17:08 schrieb Sascha Van Cauwelaert:<br><br><blockquote type="cite">I tried what you did and it works. The problem is that the project I try to interface is much more complicated than this (and I cannot modify it) but still it helps.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I will try to do the same thing with the real class GRelation. But for this, I need to use another C compiler than the standard one (I have to use the last version of gcc) and to modify the passed options (not only add some). <br></blockquote><br>Ok. This all leads to the question: What is the class GRelation really looking like? What is it that makes is so complicated? What is the "project" you are referring to? I jfgi and found those entries for GRelation:<br><br><a href="http://waffles.sourceforge.net/">http://waffles.sourceforge.net/</a><br><br>http://www.ibm.com/developerworks/linux/tutorials/l-glib/section9.html<br><br>http://www.google.de/url?sa=t&rct=j&q=grelation&source=web&cd=6&ved=0CD4QFjAF&url=http%3A%2F%2Fwww-hera-b.desy.de%2Fsubgroup%2Fsoftware%2Fclue%2FBEE-0-98%2Fgrelation%2Fmanual.ps.gz&ei=fs7PTs6EMNCEhQex6NTmDQ&usg=AFQjCNGTikFM_ttnj1PqfaEQHm9H0Ey_Ow&sig2=q_nFQ9Jxnc5OB8A_b0sjMw<br><br>Something else?<br><br> Frank<br></div></blockquote></div><br></div></body></html>