P
pallav
I'm using an old sparse matrix C library in my C++ code and I'd like
to know how to downcast a boost::shared_ptr to char *. The sparse
matrix data structure is like this:
struct sm_element_struct {
/* other fields here */
.......
char *user_word; /* user-defined word */
};
struct sm_row_struct {
.....
char *user_word; /* user-defined word */
};
struct sm_col_struct {
........
char *user_word; /* user-defined word */
};
In my c++ function, I do this:
typedef boost::shared_ptr<class Node> NodePtr; // where Node is a C++
class
static sm_matrix* convertNodeToSM(const NodePtr& n)
{
sm_matrix *M;
sm_element *elem;
sm_col *col;
M = sm_alloc(); /* allocate a sparse matrix */
unsigned int j;
NodePtr fanin;
for (unsigned int i = 0; i < n->numCubes(); ++i)
{
/* loop over all the fanin of n)
foreach_fanin(n, j, fanin)
{
switch (fanin->getValue())
{
case ZERO:
elem = sm_insert(M, i, j); // create an element at
i,j
sm_put(elem, 1); // set elem->user_word = 1
col = sm_get_col(M, static_cast<int>(j)); get the jth
column
sm_put(col, boost::lexical_cast<char *>(fanin));
break;
}
}
}
}
basically i need to store fanin (type NodePtr) into the "user_word" of
col which takes a char *. so i need to type cast. in C, i would have
just done
(char *) fanin;
but i want to know how to do this properly in C++ is
boost::lexical_cast the way to go?
and then to convert from the user word -> NodePtr I'd do this:
boost::lexical_cast<NodePtr> (col->user_word);
is this correct?
i would have preferred to use boost::ublas::mapped_matrix but i'm
finding it is not suitable to my program (minimization of Boolean
functions) so i have to use an old sparse library which is general
enough but has some support for this application domain.
i'd appreciate any help on the casting. thanks for your time.
pallav
to know how to downcast a boost::shared_ptr to char *. The sparse
matrix data structure is like this:
struct sm_element_struct {
/* other fields here */
.......
char *user_word; /* user-defined word */
};
struct sm_row_struct {
.....
char *user_word; /* user-defined word */
};
struct sm_col_struct {
........
char *user_word; /* user-defined word */
};
In my c++ function, I do this:
typedef boost::shared_ptr<class Node> NodePtr; // where Node is a C++
class
static sm_matrix* convertNodeToSM(const NodePtr& n)
{
sm_matrix *M;
sm_element *elem;
sm_col *col;
M = sm_alloc(); /* allocate a sparse matrix */
unsigned int j;
NodePtr fanin;
for (unsigned int i = 0; i < n->numCubes(); ++i)
{
/* loop over all the fanin of n)
foreach_fanin(n, j, fanin)
{
switch (fanin->getValue())
{
case ZERO:
elem = sm_insert(M, i, j); // create an element at
i,j
sm_put(elem, 1); // set elem->user_word = 1
col = sm_get_col(M, static_cast<int>(j)); get the jth
column
sm_put(col, boost::lexical_cast<char *>(fanin));
break;
}
}
}
}
basically i need to store fanin (type NodePtr) into the "user_word" of
col which takes a char *. so i need to type cast. in C, i would have
just done
(char *) fanin;
but i want to know how to do this properly in C++ is
boost::lexical_cast the way to go?
and then to convert from the user word -> NodePtr I'd do this:
boost::lexical_cast<NodePtr> (col->user_word);
is this correct?
i would have preferred to use boost::ublas::mapped_matrix but i'm
finding it is not suitable to my program (minimization of Boolean
functions) so i have to use an old sparse library which is general
enough but has some support for this application domain.
i'd appreciate any help on the casting. thanks for your time.
pallav