expression const_cast_( const std::shared_ptr< llvm::LLVMContext > &context, const std::shared_ptr< ir_builder_t > &ir_builder, const type cast_to, const expression &value ) { if( type_traits::is_reference( value.type() ) || type_traits::is_pointer( value.type() ) ) { if( value.type().which() == cast_to.which() ) return remove_const_cast( context, ir_builder, cast_to, value ); else if( type_traits::is_reference( value.type() ) && type_traits::is_pointer( cast_to ) ) { const auto dereferenced = remove_reference( context, ir_builder, value ); return const_cast_( context, ir_builder, cast_to, dereferenced ); } else if( type_traits::is_rvalue_reference( value.type() ) && type_traits::is_lvalue_reference( cast_to ) ) return reference_cast( context, ir_builder, cast_to, value ); } throw exceptions::invalid_cast(); }
PyObject* wrap_property_helper(PyTypeObject* type,const char* name,getter get_wrapper,setter set_wrapper,void* getset) { // Make a PyGetSetDef PyGetSetDef* def = (PyGetSetDef*)malloc(sizeof(PyGetSetDef)); memset(def,0,sizeof(PyGetSetDef)); def->name = const_cast_(name); def->get = get_wrapper; def->set = set_wrapper; def->closure = getset; // Allocate descriptor PyObject* descr = PyDescr_NewGetSet(type,def); if (!descr) throw_python_error(); return descr; }
PolygonSoup::PolygonSoup(Array<const int> counts, Array<const int> vertices, const int min_nodes) : counts(counts) , vertices(vertices) , node_count(max(0,min_nodes)) , half_edge_count(counts.sum()) { // Assert validity and compute counts GEODE_ASSERT(half_edge_count==vertices.size()); for (int i=0;i<counts.size();i++) GEODE_ASSERT(counts[i]>=3); // Polygons must be at least triangles for (int i=0;i<vertices.size();i++) { GEODE_ASSERT(vertices[i]>=0); const_cast_(node_count) = max(node_count,vertices[i]+1); } }