Exemple #1
0
		void shdt_test_send_tuples() {
			
			Shdt::Writer w(&sender, buffer_, bufsize_,
					Shdt::write_callback_t::from_method<ExampleApplication, &ExampleApplication::shdt_test_receive_tuples>(this));
			w.write_header(table_size_, 3);
			
			for(block_data_t** t = test_tuples_; t[0]; t += 3) {
				Tuple tuple;
				
				#if USE_CODEC
					block_data_t *s = Codec::encode(t[0]);
					tuple.set(0, s); cstr_size_ += strlen((char*)s) + 1;
					s = Codec::encode(t[1]);
					tuple.set(1, s); cstr_size_ += strlen((char*)s) + 1;
					s = Codec::encode(t[2]);
					tuple.set(2, s); cstr_size_ += strlen((char*)s) + 1;
				
				#else
					tuple.set(0, t[0]); cstr_size_ += strlen((char*)t[0]) + 1;
					tuple.set(1, t[1]); cstr_size_ += strlen((char*)t[1]) + 1;
					tuple.set(2, t[2]); cstr_size_ += strlen((char*)t[2]) + 1;
				#endif
				
				w.write_tuple(tuple);
				
				#if USE_CODEC
					::get_allocator().free_array(tuple.get(0));
					::get_allocator().free_array(tuple.get(1));
					::get_allocator().free_array(tuple.get(2));
				#endif
			}
			
			w.flush();
		}
bool toVector(PyObjectPtr obj, std::vector<double>& result)
{
    bool knownType = true;

    if(NdArray::check(obj))
    {
        NdArray ndarray = {obj};
        const unsigned size = ndarray.size();
        result.resize(size);

        const int ndim = ndarray.ndim();
        if(ndim != 1)
            throw std::runtime_error("Array object has " + std::to_string(ndim)
                                     + " dimensions, expected 1");
        if(!ndarray.isDouble())
            throw std::runtime_error("Array object does not contain doubles");

        for(unsigned i = 0; i < size; i++)
            result[i] = ndarray.get(i);
    }
    else if(List::check(obj))
    {
        List list = {obj};
        const unsigned size = list.size();
        result.resize(size);

        for(unsigned i = 0; i < size; i++)
        {
            if(!list.isDouble(i))
                throw std::runtime_error(
                    "List object contains item that is not a double at index "
                    + std::to_string(i));
            result[i] = list.get(i);
            throwPythonException();
        }
    }
    else if(Tuple::check(obj))
    {
        Tuple tuple = {obj};
        const unsigned size = tuple.size();
        result.resize(size);

        for(unsigned i = 0; i < size; i++)
        {
            if(!tuple.isDouble(i))
                throw std::runtime_error(
                    "Tuple object contains item that is not a double at index "
                    + std::to_string(i));
            result[i] = tuple.get(i);
            throwPythonException();
        }
    }
    else
    {
        knownType = false;
    }

    return knownType;
}
Exemple #3
0
		void shdt_test_receive_tuples(Shdt::Writer& w) { //block_data_t *buffer, size_type buffer_size) {
			//debug_buffer<Os, 16, Os::Debug>(debug_, w.buffer(), w.buffer_used());
			
			packets_++;
			shdt_size_ += w.buffer_used();
			Shdt::Reader r(&receiver, w.buffer(), w.buffer_used());
			
			bool found;
			
			while(true) {
				Tuple t;
				found = r.read_tuple(t);
				if(!found) { break; }
				
				for(size_type i = 0; i < 3; i++, verify_idx_++) {
					char *s;
					#if USE_CODEC
						s = (char*)Codec::decode(t.get(i));
					#else
						s = (char*)t.get(i);
					#endif
					
					
					//DBG("t[%d]=%s test[%d]=%s", i, t.get(i), verify_idx_, test_tuples_[verify_idx_]);
					if(strcmp(s, (char*)test_tuples_[verify_idx_]) != 0) {
						debug_->debug("\x1b[31merror: t[%d]=%s != vrfy[%d]=%s\x1b[m", (int)i, (char*)t.get(i),
								(int)verify_idx_, (char*)test_tuples_[verify_idx_]);
						assert(false);
					}
					
					#if USE_CODEC
						::get_allocator().free_array(s);
					#endif
				}
			}
			
			w.reuse_buffer();
		}