Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-03-21 01:55:07 +0300
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-03-21 01:55:07 +0300
commita0682124459d870e53f1bc5d9b1d2930e5a907f3 (patch)
treea8bd700614557ceeea6a57d6a58306948292a5f9 /source/blender/freestyle/intern/view_map/Functions0D.h
parentac0918a1beb4c40dab17a914ca58042642a266d0 (diff)
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text(). Before these changes were made, the operator() methods of predicates and functions, for example, returned a value of various types such as bool, double and Vec2f. These returned values were not capable to represent an error state in many cases. Now the operator() methods always return 0 on normal exit and -1 on error. The original returned values are stored in the "result" member variables of the predicate/function classes. This means that if we have a code fragment like below: UnaryPredicate1D& pred; Interface1D& inter; if (pred(inter)) { /* do something */ } then we have to rewrite it as follows: UnaryPredicate1D& pred; Interface1D& inter; if (pred(inter) < 0) return -1; /* an error in pred() is propagated */ if (pred.result) { /* do something */ } Suppose that pred is a user-defined predicate in Python, i.e. the predicate is likely error-prone (especially when debugging the predicate). The first code fragment shown above prevents the proper error propagation because the boolean return value of UnaryPredicate1D::operator() cannot inform the occurrence of an error to the caller; the second code fragment can. In addition to the operator() methods of predicates and functions, similar improvements have been made to all other C++ API functions and methods that are involved in the execution of user-defined Python code snippets. Changes in the signatures of functions and methods are summarized as follows (note that all subclasses of listed classes are also subject to the changes). Old signatures: virtual void Iterator::increment(); virtual void Iterator::decrement(); virtual void ChainingIterator::init(); virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it); static void Operators::select(UnaryPredicate1D& pred); static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred, UnaryFunction1D_void& modifier); static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred); static void Operators::bidirectionalChain(ChainingIterator& it, UnaryPredicate1D& pred); static void Operators::bidirectionalChain(ChainingIterator& it); static void Operators::sequentialSplit(UnaryPredicate0D& startingPred, UnaryPredicate0D& stoppingPred, float sampling = 0); static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0); static void Operators::recursiveSplit(UnaryFunction0D<double>& func, UnaryPredicate1D& pred, float sampling = 0); static void Operators::recursiveSplit(UnaryFunction0D<double>& func, UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0); static void Operators::sort(BinaryPredicate1D& pred); static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders); virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it); virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2); virtual bool UnaryPredicate1D::operator()(Interface1D& inter); virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2); virtual void StrokeShader::shade(Stroke& ioStroke) const; virtual T UnaryFunction0D::operator()(Interface0DIterator& iter); virtual T UnaryFunction1D::operator()(Interface1D& inter); New signatures: virtual int Iterator::increment(); virtual int Iterator::decrement(); virtual int ChainingIterator::init(); virtual int ChainingIterator::traverse(const AdjacencyIterator &it); static int Operators::select(UnaryPredicate1D& pred); static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred, UnaryFunction1D_void& modifier); static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred); static int Operators::bidirectionalChain(ChainingIterator& it, UnaryPredicate1D& pred); static int Operators::bidirectionalChain(ChainingIterator& it); static int Operators::sequentialSplit(UnaryPredicate0D& startingPred, UnaryPredicate0D& stoppingPred, float sampling = 0); static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0); static int Operators::recursiveSplit(UnaryFunction0D<double>& func, UnaryPredicate1D& pred, float sampling = 0); static int Operators::recursiveSplit(UnaryFunction0D<double>& func, UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0); static int Operators::sort(BinaryPredicate1D& pred); static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders); virtual int UnaryPredicate0D::operator()(Interface0DIterator& it); virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2); virtual int UnaryPredicate1D::operator()(Interface1D& inter); virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2); virtual int StrokeShader::shade(Stroke& ioStroke) const; virtual int UnaryFunction0D::operator()(Interface0DIterator& iter); virtual int UnaryFunction1D::operator()(Interface1D& inter);
Diffstat (limited to 'source/blender/freestyle/intern/view_map/Functions0D.h')
-rwxr-xr-xsource/blender/freestyle/intern/view_map/Functions0D.h73
1 files changed, 41 insertions, 32 deletions
diff --git a/source/blender/freestyle/intern/view_map/Functions0D.h b/source/blender/freestyle/intern/view_map/Functions0D.h
index 24d2edac094..dbd7d558a47 100755
--- a/source/blender/freestyle/intern/view_map/Functions0D.h
+++ b/source/blender/freestyle/intern/view_map/Functions0D.h
@@ -94,16 +94,17 @@ UnaryFunction0D() { py_uf0D = 0;}
* the function.
* \return the result of the function of type T.
*/
- virtual T operator()(Interface0DIterator& iter) {
+ virtual int operator()(Interface0DIterator& iter) {
string name( py_uf0D ? PyString_AsString(PyObject_CallMethod(py_uf0D, "getName", "")) : getName() );
if( py_uf0D && PyObject_HasAttrString(py_uf0D, "__call__") ) {
- Director_BPy_UnaryFunction0D___call__( this, py_uf0D, iter);
- return result;
+ if (Director_BPy_UnaryFunction0D___call__( this, py_uf0D, iter) < 0) {
+ return -1;
+ }
} else {
cerr << "Warning: " << name << " operator() not implemented" << endl;
- return T();
}
+ return 0;
}
};
@@ -146,8 +147,9 @@ namespace Functions0D {
return "GetXF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter) {
- return iter->getX();
+ int operator()(Interface0DIterator& iter) {
+ result = iter->getX();
+ return 0;
}
};
@@ -161,8 +163,9 @@ namespace Functions0D {
return "GetYF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter) {
- return iter->getY();
+ int operator()(Interface0DIterator& iter) {
+ result = iter->getY();
+ return 0;
}
};
@@ -176,8 +179,9 @@ namespace Functions0D {
return "GetZF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter) {
- return iter->getZ();
+ int operator()(Interface0DIterator& iter) {
+ result = iter->getZ();
+ return 0;
}
};
@@ -191,8 +195,9 @@ namespace Functions0D {
return "GetProjectedXF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter) {
- return iter->getProjectedX();
+ int operator()(Interface0DIterator& iter) {
+ result = iter->getProjectedX();
+ return 0;
}
};
@@ -206,8 +211,9 @@ namespace Functions0D {
return "GetProjectedYF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter) {
- return iter->getProjectedY();
+ int operator()(Interface0DIterator& iter) {
+ result = iter->getProjectedY();
+ return 0;
}
};
@@ -221,8 +227,9 @@ namespace Functions0D {
return "GetProjectedZF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter) {
- return iter->getProjectedZ();
+ int operator()(Interface0DIterator& iter) {
+ result = iter->getProjectedZ();
+ return 0;
}
};
@@ -236,8 +243,9 @@ namespace Functions0D {
return "GetCurvilinearAbscissaF0D";
}
/*! the () operator.*/
- float operator()(Interface0DIterator& iter) {
- return iter.t();
+ int operator()(Interface0DIterator& iter) {
+ result = iter.t();
+ return 0;
}
};
@@ -251,8 +259,9 @@ namespace Functions0D {
return "GetParameterF0D";
}
/*! the () operator.*/
- float operator()(Interface0DIterator& iter) {
- return iter.u();
+ int operator()(Interface0DIterator& iter) {
+ result = iter.u();
+ return 0;
}
};
@@ -269,7 +278,7 @@ namespace Functions0D {
return "VertexOrientation2DF0D";
}
/*! the () operator.*/
- Vec2f operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// VertexOrientation3DF0D
@@ -285,7 +294,7 @@ namespace Functions0D {
return "VertexOrientation3DF0D";
}
/*! the () operator.*/
- Vec3f operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// Curvature2DAngleF0D
@@ -301,7 +310,7 @@ namespace Functions0D {
return "Curvature2DAngleF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// ZDiscontinuity
@@ -319,7 +328,7 @@ namespace Functions0D {
return "ZDiscontinuityF0D";
}
/*! the () operator.*/
- real operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// Normal2DF0D
@@ -335,7 +344,7 @@ namespace Functions0D {
return "Normal2DF0D";
}
/*! the () operator.*/
- Vec2f operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// MaterialF0D
@@ -358,7 +367,7 @@ namespace Functions0D {
return "MaterialF0D";
}
/*! the () operator.*/
- FrsMaterial operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// ShapeIdF0D
@@ -379,7 +388,7 @@ namespace Functions0D {
return "ShapeIdF0D";
}
/*! the () operator.*/
- Id operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// QiF0D
@@ -400,7 +409,7 @@ namespace Functions0D {
return "QuantitativeInvisibilityF0D";
}
/*! the () operator.*/
- unsigned int operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// CurveNatureF0D
@@ -415,7 +424,7 @@ namespace Functions0D {
return "CurveNatureF0D";
}
/*! the () operator.*/
- Nature::EdgeNature operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// GetShapeF0D
@@ -430,7 +439,7 @@ namespace Functions0D {
return "GetShapeF0D";
}
/*! the () operator.*/
- ViewShape* operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// GetOccludersF0D
@@ -445,7 +454,7 @@ namespace Functions0D {
return "GetOccludersF0D";
}
/*! the () operator.*/
- std::vector<ViewShape*> operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};
// GetOccludeeF0D
@@ -460,7 +469,7 @@ namespace Functions0D {
return "GetOccludeeF0D";
}
/*! the () operator.*/
- ViewShape* operator()(Interface0DIterator& iter);
+ int operator()(Interface0DIterator& iter);
};