Brian Neal | 1 Feb 2005 01:34
Picon
Favicon

Rationale for intrusive_ptr?

Hi, I need some help understanding when and why you
would want to use intrusive_ptr. Does someone have an
example? I didn't get much out of the current
documentation for it. Thank you. 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
Nat Goodspeed | 1 Feb 2005 03:58
Favicon

RE: Rationale for intrusive_ptr?

> -----Original Message-----
> From: boost-users-bounces <at> lists.boost.org [mailto:boost-users-
> bounces <at> lists.boost.org] On Behalf Of Brian Neal
> Sent: Monday, January 31, 2005 7:34 PM
> To: boost-users <at> lists.boost.org
> Subject: [Boost-users] Rationale for intrusive_ptr?
> 
> Hi, I need some help understanding when and why you
> would want to use intrusive_ptr. Does someone have an
> example? I didn't get much out of the current
> documentation for it. Thank you.

[Nat] Consider:

class MyClass;

void some_func(const boost::shared_ptr<MyClass>& ptr);

class MyClass
{
public:
    void process()
    {
        // BAD THINGS HAPPEN!
        some_func(boost::shared_ptr<MyClass>(this));
    }
};

In our current project, we've been bitten more than once :-( by
situations that are analogous but less obvious. Inside a member
(Continue reading)

Yuval Ronen | 1 Feb 2005 07:50
Picon
Favicon

Re: Two issues with lexical_cast

>>I haven't tried it, but I have a feeling that it will work for string
>>literals, but not for c-string variables
> 
> 
> With "c-string variables", do you mean pointer to char? Or something like
> MFC's CString?

pointer to char

> Anyway, the first is supported as before. The above just ensures that the
> type passed to the rest of lexical_cast is the same type it used to be, when
> it used pass by value. So arrays will decay to pointers, and everything else
> will pass through unaltered. I ran the above through the unit test, and it
> passes all, on the three compilers I tested it with. I've since talked with
> Kevlin, and this was also what he had in mind, to make pass by const
> reference work.

Ok. As I said, this comment was made without trying it, so it's quite 
possible (and even probable) that I was mistaking. I'll be more careful 
next time (spank on the tush for me...)
Paul | 1 Feb 2005 09:23
Picon
Favicon

Re: Rationale for intrusive_ptr?


Brian Neal wrote:
> Hi, I need some help understanding when and why you
> would want to use intrusive_ptr. Does someone have an
> example? I didn't get much out of the current
> documentation for it. Thank you. 

For the Coin library (an OpenInventor implementation).

// declare add-ref/rm-ref functions
inline void intrusive_ptr_add_ref( SoNode* n ) { n->ref(); }
inline void intrusive_ptr_release( SoNode* n ) { n->unref(); }

now:
       intrusive_ptr<SoGroup> root;
will perform like a shared_ptr, except it will do ref() and unref() 
instead of deletes.

Very useful.

Paul
Austin Bingham | 1 Feb 2005 16:33
Picon
Gravatar

uBLAS sparse_matrix "default" value

Apparently the wheels of the ublas mailing list move slowly, so I'm
asking this question here.

Is there any way to set the "default" value of a sparse_matrix?
sparse_matrix seems to guarantee that you always get a value when you
access an index, even if that index hasn't been explicitly set. For
sparse_matrix<float>, for instance, you get 0. Is there any way to
specify this value? That is, if I wanted to get back, say, -1 for
unset entries, is there a way to do this? There's no direct mention of
this that I can find, although there were some discussions of
zero-constructors or somesuch that may have been dealing with this
question. Thanks.

Austin Bingham
Yuval Ronen | 1 Feb 2005 16:49
Picon
Favicon

Re: [variant] is_a/can_be

> > Hi.
> > I encountered the need to query a boost::variant to which type it
> > currently contain. I'm talking about something like:
> >
> > variant<int, string> v(3);
> > assert(v.is_a<int>());
> > assert(!v.is_a<string>());
>
> Take a look at get(), it's almost what you need.  Unfortunately, it
> compiles even when the type cannot be inside the variant.  This can be
> fixed with mpl::contains:
>
> template<typename T, typename Variant>
> bool variant_is_a(const Variant& v)
> {
>       BOOST_MPL_ASSERT(( boost::mpl::contains<typename
Variant::types,T> ));
>       return boost::get<T>(&v) != 0;
> }
>
> There should be a version of get that works as variant_is_a above.  IMHO,
> the current behaviour is more dangerous than that of variant_is_a, so
> get() should be changed and maybe a new function be created that keeps the
> current behaviour.  Some code may break with this change with a compile
> error that would go away if the other version of get is used.

Your code works beautifully. I really hope this feature will find its way to
the variant library.
Benjamin Schmeling | 1 Feb 2005 19:38
Picon
Picon

problems with constructor/implicitly_convertible

Hi,
I have defined the following:

bigint* bigint_constructor(long_ l){
   return new bigint(to_bigint(l));
}

class_<bigint>("bigint")
.def("__init__", make_constructor(bigint_constructor))
....
....

implicitly_convertible<boost::python::long_, bigint>();

Now I want to have a implicit conversion from long_ to bigint. My 
original c++ class has no constructor with long_ but my python-bigint 
class. The compiler tries to find one on c++ bigint and doesn't find it. 
How should I use implicitly_convertible to reach my goal?

Benjamin
Grek | 1 Feb 2005 21:38
Picon
Favicon

Compilation Error

Hi:
 
I am a newbie to the world of Boost.
 
I have a problem in compiling a program.  I do not know how to set the path to compile the attached code.
 
My platform is Cygwin
gcc version 3.3.3
 
The boost_1_32_0 subdirectory resides in the Cygwin directory.
 
I tried the following,
 
g++ boost_1_32_0/boost/graph/sourcecode.cpp
 
and it displays the message
boost/config.hpp : No such file or directory
boost/graph/graph_traits.hpp : No such file or directory
boost/graph/adjacency_list.hpp : No such file or directory
boost/graph/dijkstra_shortest_paths.hpp : No such file or directory
 
followed by more error messages. Please refer to the attached code and help me out.
 
Thanks in advance.
 
Sourcecode.cpp
******************************************************************************
#include <boost/config.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
using namespace boost;
float maximum(float a[], float mx, int n){
  float max=mx;
  for(int i=0; i<n; ++i){
    if(max < a[i]){
      max=a[i];
    }
  }
  return max;
}
int main()
{
  int num_nodes = 10000;   
  int num_PPIs = 50000;   
  char node[num_nodes][10], p1[num_PPIs][10], p2[num_PPIs][10];
  char name[num_nodes];
  float wt[num_PPIs], apl, dia, path[num_nodes];
  int i, j, l, l1, l2, mx_len=num_nodes, pl[mx_len];
  typedef adjacency_list < listS, vecS, directedS,
    no_property, property < edge_weight_t, float > > graph_t;
  typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
  typedef graph_traits < graph_t >::edge_descriptor edge_descriptor;
  typedef std::pair<int, int> Edge;
  std::ifstream INF1 ("./data/None.conversion");
  std::ifstream INF2 ("./data/None.before");
  if(!INF1){
    std::cerr << "Cannot find INF1 file." << std::endl;
    return EXIT_FAILURE;
  }
  if(!INF2){
    std::cerr << "Cannot find INF2 file." << std::endl;
    return EXIT_FAILURE;
  }
  //read data
  i=0;
  while(INF1 >> num_nodes >> node[i]){
    ++i;
  }
  INF1.close();
  num_nodes=i;
  i=0;
  while(INF2 >> p1[i] >> p2[i] >> wt[i]){
    wt[i]=1.0; 
    ++i;
  }
  INF2.close();
  num_PPIs=i;
  //
  Edge edge_array[num_PPIs];
&n bsp; for(i=0; i<num_PPIs; ++i){
    for(j=0; j<num_nodes; ++j){
      if(stricmp(p1[i],node[j]) == 0){
 edge_array[i].first=j;
       }
    }
    for(j=0; j<num_nodes; ++j){
      if(stricmp(p2[i],node[j]) == 0){
 edge_array[i].second=j;
      }
    }
  }
  //
  int num_arcs = sizeof(edge_array) / sizeof(Edge);
  std::cout << "0   None   " << num_PPIs << "   " << num_nodes;
    graph_t g(edge_array, edge_array + num_arcs, wt, num_nodes);
    property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);
    std::vector<vertex_descriptor> p(num_vertices(g));
    std::vector< float> d(num_vertices(g));
    //
    l1=0;
    l2=0;
    dia=0;
    for(j=1; j<mx_len; ++j){
      pl[j]=0;
    }
    //
    for(int src=0; src<num_nodes; ++src){
      vertex_descriptor s = vertex(src, g);
      dijkstra_shortest_paths(g, s, predecessor_map(&p[0]).distance_map(&d[0]));
      for(j=0; j<num_nodes; ++j){
 if(j == p[j]){ //set self-looping node to zero distance
   d[j]=0;
 }
 if(d[j] > 10000){ //set non-connecting node to zero distance
   d[j]=0;
 }
 path[j]=d[j];
 pl[int(d[j]+0.5)]=pl[int(d[j]+0.5)]+1;
      }
      dia=maximum(path,dia,num_no des);
    }                                 
    for(l=1; l<=int(dia); ++l){
      l1=l1+pl[l]*l;
      l2=l2+pl[l];
    }
    apl=float(l1)/float(l2);
    std::cout << "   " << apl << "   " << l1 << "   " << l2 << "   " << dia << std::endl;
  return EXIT_SUCCESS;
}
**********************************************************************************
 
Cheers
 
Grek
 
 
 

Do you Yahoo!?
Yahoo! Search presents - Jib Jab's 'Second Term'
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Rene Rivera | 1 Feb 2005 22:51

Re: Compilation Error

Grek wrote:
> I am a newbie to the world of Boost.
>  
> I have a problem in compiling a program.  I do not know how to set the 
> path to compile the attached code.
>  
> My platform is Cygwin
> gcc version 3.3.3
>  
> The boost_1_32_0 subdirectory resides in the Cygwin directory.

Not generally a good idea.

> I tried the following,
>  
> g++ boost_1_32_0/boost/graph/sourcecode.cpp
>  
> and it displays the message
> boost/config.hpp : No such file or directory

You need to add to the include path to your compiler. See:

http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Preprocessor-Options.html#Preprocessor-Options
Preprocessor Options - Using the GNU Compiler Collection (GCC)

And for Boost related building/setup see:

http://www.boost.org/more/getting_started.html
Getting Started

--

-- 
-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. - http://redshift-software.com
-- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq
samantha Quark | 1 Feb 2005 22:30
Picon
Favicon

regex_token_iterator bug?

Dear all,
 I just played a little bit with the
regex_token_iterator ( boost v 1.32) and modified the
"html" example. 
I found this (strange?) behavior when i "tokenize" a
string.

while (i != j)
{
  std::cout << i++->str().length() << std::endl;
}

crashes at runtime at the last sub-match of a match
with:
mtest: ../boost_1_32_0/boost/shared_ptr.hpp:253: T*
boost::shared_ptr<T>::operator->() const [with T =
boost::regex_token_iterator_implementation<__gnu_cxx::__normal_iterator<const
char*, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, char,
boost::regex_traits<char>, std::allocator<char> >]:
Assertion `px != 0' failed.
zsh: 24497 abort      mtest test.html

Whereas:

while (i != j)
{
  std::cout << i->str().length() << std::endl;
  i++;
}

works fine.

Is this behavior a bug, or is it correct, that the
first version does not work, if yes, why?

Cheers, Joe.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Gmane