//#####################################################################
// Function Print
//#####################################################################
template<class RW> void Read_Write<ARRAY_COLLECTION,RW>::
Print(std::ostream& output,const ARRAY_COLLECTION& object,const int p)
{
    if(p<1 || p>object.number) throw INDEX_ERROR("Index out of range");
    for(ATTRIBUTE_INDEX i(1);i<=object.arrays.m;i++){
        const ARRAY_COLLECTION_ELEMENT_BASE* entry=object.arrays(i);
        const READ_WRITE_ARRAY_COLLECTION_FUNCTIONS* read_write_functions=Read_Write_Array_Collection_Registry().Get_Pointer(Type_Only(entry->Hashed_Id()));
        if(!read_write_functions || !read_write_functions->Print)
            PHYSBAM_FATAL_ERROR(STRING_UTILITIES::string_sprintf("No print registered for id %i (type %s)\n",Value(entry->id),typeid(*entry).name()));
        read_write_functions->Print(output,*entry,p);}
}
Example #2
0
static PyObject *
GMPy_XMPZ_Method_SubScript(XMPZ_Object* self, PyObject* item)
{
    CTXT_Object *context = NULL;

    CHECK_CONTEXT(context);

    if (PyIndex_Check(item)) {
        Py_ssize_t i;

        i = PyIntOrLong_AsSsize_t(item);
        if (i == -1 && PyErr_Occurred()) {
            INDEX_ERROR("argument too large to be converted to an index");
            return NULL;
        }
        if (i < 0) {
            i += mpz_sizeinbase(self->z, 2);
        }
        return PyIntOrLong_FromLong(mpz_tstbit(self->z, i));
    }
    else if (PySlice_Check(item)) {
        Py_ssize_t start, stop, step, slicelength, cur, i;
        MPZ_Object *result;

#if PY_VERSION_HEX > 0x030200A4
        if (PySlice_GetIndicesEx(item,
#else
        if (PySlice_GetIndicesEx((PySliceObject*)item,
#endif
                         mpz_sizeinbase(self->z, 2),
                         &start, &stop, &step, &slicelength) < 0) {
            return NULL;
        }

        if ((step < 0 && start < stop) || (step > 0 && start > stop)) {
            stop = start;
        }

        if (!(result = GMPy_MPZ_New(context))) {
            return NULL;
        }

        mpz_set_ui(result->z, 0);
        if (slicelength > 0) {
            for (cur = start, i = 0; i < slicelength; cur += step, i++) {
                if (mpz_tstbit(self->z, cur)) {
                    mpz_setbit(result->z, i);
                }
            }
        }
        return (PyObject*)result;
    }
    else {