Dear list,
I am using std::vector<bool> (bit_vector) to store my bit sequence. To
access the same sequence from C (to expose to a python module), I need
to know the pointer and offset of vector::<bool>::iterator (or
reference). However, given a std::vector<bool> a, all a.begin(), a[0]
etc are instances of a proxy class so I can not do things like
&*a.begin(). Is there a safe way to get the information I need?
Many thanks in advance.
Bo 8 3515
* Bo Peng: I am using std::vector<bool> (bit_vector) to store my bit sequence. To access the same sequence from C (to expose to a python module), I need to know the pointer and offset of vector::<bool>::iterator (or reference). However, given a std::vector<bool> a, all a.begin(), a[0] etc are instances of a proxy class so I can not do things like &*a.begin(). Is there a safe way to get the information I need?
Something like
void python( int const bitValues[], int nValues );
void callPython( std::vector<bool> const& bits )
{
std::vector<int> const values( bits.begin(), bits.end() );
python( &values[0], safe_cast<int>( values.size() ) );
}
where "safe_cast" is your favorite safe cast from one integral type to
another, presumably aborting or throwing an exception if the value can't
be represented by the destination type.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Bo Peng wrote: I am using std::vector<bool> (bit_vector) to store my bit sequence. To access the same sequence from C (to expose to a python module), I need to know the pointer and offset of vector::<bool>::iterator (or reference). However, given a std::vector<bool> a, all a.begin(), a[0] etc are instances of a proxy class so I can not do things like &*a.begin(). Is there a safe way to get the information I need?
No. Bits have no separate address.
V
Victor Bazarov wrote: Bo Peng wrote:
I am using std::vector<bool> (bit_vector) to store my bit sequence. To access the same sequence from C (to expose to a python module), I need to know the pointer and offset of vector::<bool>::iterator (or reference). However, given a std::vector<bool> a, all a.begin(), a[0] etc are instances of a proxy class so I can not do things like &*a.begin(). Is there a safe way to get the information I need?
No. Bits have no separate address.
Really? What I need is actually the starting point of the bits. I.e.,
&*vec.begin() if the vector is not vector<bool>. It should not be too
diffcult since bit_vector always starts from the beginning of a WORD.
Cheers,
Bo
Bo Peng wrote: Victor Bazarov wrote:
Bo Peng wrote:
I am using std::vector<bool> (bit_vector) to store my bit sequence. To access the same sequence from C (to expose to a python module), I need to know the pointer and offset of vector::<bool>::iterator (or reference). However, given a std::vector<bool> a, all a.begin(), a[0] etc are instances of a proxy class so I can not do things like &*a.begin(). Is there a safe way to get the information I need? No. Bits have no separate address.
Really? What I need is actually the starting point of the bits. I.e., &*vec.begin() if the vector is not vector<bool>. It should not be too diffcult since bit_vector always starts from the beginning of a WORD.
There is no requirement that 'vector<bool>' keeps its bits in the same
array, same value, or same {whatever_other_collection_you_can_think_of}.
So, if you _know_ that those bits are a contiguous representation of some
kind of integral value (or whatever you think they are), you know already
where and/or how to get them.
All I can suggest is to repackage them as you need them, just like Alf
explained.
V
Victor Bazarov wrote: All I can suggest is to repackage them as you need them, just like Alf explained.
The problem is that the goal of this python module is to *expose* the
underlying vector<bool> (other vectors are easy and have been done) and
allow users to read/write the vector directly. For example
v = getVector(); # return a python object v
print v
print v[2]
v[0] = 1
v[3] = 0
Bo
> For that you need to provide a wrapper to the python side.
Exactly. I have already working code for other vectors. The python
wrapper object knows vector type and starting pointer and can correctly
read/write vector items. In the case of vector<bool>, I am unable to get
the starting address.
The only way out may be extending python in C++, instead of C. I mean,
store a vector reference directly instead of pointer. I really do not
know how to do this since all examples of extending Python is written in C.
Cheers,
Bo
* Bo Peng: Victor Bazarov wrote:
All I can suggest is to repackage them as you need them, just like Alf explained.
The problem is that the goal of this python module is to *expose* the underlying vector<bool> (other vectors are easy and have been done) and allow users to read/write the vector directly. For example
v = getVector(); # return a python object v print v print v[2] v[0] = 1 v[3] = 0
For that you need to provide a wrapper to the python side.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
On Tue, 31 Jan 2006 18:54:00 -0600, Bo Peng <bp***@rice.edu> wrote: For that you need to provide a wrapper to the python side.
Exactly. I have already working code for other vectors. The python wrapper object knows vector type and starting pointer and can correctly read/write vector items. In the case of vector<bool>, I am unable to get the starting address.
vector<bool> is an exception to all other vectors. You cannot access
its storage directly like a buffer, neither in C++ nor in any other
language. As the C++ standard says, the reference returned by
vector<bool>::operator[] is some kind of proxy class that lets you
read and write individual bool elements, but that's all.
If you can't do it in C++, "extending Python" won't help, either.
The only way out may be extending python in C++, instead of C. I mean, store a vector reference directly instead of pointer. I really do not know how to do this since all examples of extending Python is written in C.
Cheers, Bo
--
Bob Hairgrove No**********@Home.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jim Campbell |
last post by:
Suppose I wanted to a class to contain a pointer, but I didn't want to
make the copy constructor or assignment operator reinitialize this
pointer. (Think of a class that contains an mmapped pointer...
|
by: Ruediger Knoerig |
last post by:
In my current project I used templates to provide an
universial interface to vector objects. For this purpose I declared
two methods with an additional template argument:
template<class Vector>...
|
by: Daniel Aarno |
last post by:
Consider the following code:
typedef int A;
class B {
public:
B(A& var) : m_var(var) {}
virtual ~B() {}
protected:
|
by: C# Expert |
last post by:
I am using managed c++ code.
I have created i function with one argument that is reference to
double.
fun(double& d)
When I see it in object browser in visual studio 2005, it shows pointer...
|
by: asdf |
last post by:
C++ allows a reference to a pointer, but doesn't allow a pointer to a
reference, why?
|
by: Mohan |
last post by:
Hi,
What are the advantages/disadvantages of using a pointer instead of
Reference in the Copy Constructor ?
For Example,
Writing the Copy constructor for the Class "Temp" as below,
...
|
by: sulekhasweety |
last post by:
dear all,
can anyone explain the differences between pointer variable and
reference variables ?
|
by: swathi amireddy |
last post by:
Currently im trying to migrate a project from .net 1.1 to 2.0.While running the application its giving an exception for the below code while doing the update operation:
protected void...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |