MCPcopy Create free account
hub / github.com/AngusJohnson/Clipper2 / SaveTest

Function SaveTest

CPP/Utils/ClipFileSave.cpp:249–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249bool SaveTest(const std::string& filename, bool append,
250 const Paths64* subj, const Paths64* subj_open, const Paths64* clip,
251 int64_t area, int64_t count, ClipType ct, FillRule fr)
252{
253 string line;
254 bool found = false;
255 int last_cap_pos = 0, curr_cap_pos = 0;
256 int64_t last_test_no = 0;
257 if (append && FileExists(filename)) //get the number of the preceding test
258 {
259 ifstream file;
260 file.open(filename, std::ios::binary);
261 if (!file || !file.good()) return false;
262 BMH_Search bmh = BMH_Search(file, "CAPTION:");
263 while (bmh.FindNext()) ;
264 if (bmh.LastFound())
265 {
266 line.assign(bmh.LastFound()+8, bmh.FindNextEndLine());
267 string::const_iterator s_it = line.cbegin(), s_end = line.cend();
268 GetInt(s_it, s_end, last_test_no);
269 }
270 }
271 else if (FileExists(filename))
272 remove(filename.c_str());
273
274 ++last_test_no;
275
276 std::ofstream source;
277 if (append && FileExists(filename))
278 source.open(filename, ios_base::app | ios_base::ate);
279 else
280 source.open(filename);
281
282 string cliptype_string;
283 switch (ct)
284 {
285 case ClipType::NoClip: cliptype_string = "NOCLIP"; break;
286 case ClipType::Intersection: cliptype_string = "INTERSECTION"; break;
287 case ClipType::Union: cliptype_string = "UNION"; break;
288 case ClipType::Difference: cliptype_string = "DIFFERENCE"; break;
289 case ClipType::Xor: cliptype_string = "XOR"; break;
290 }
291
292 string fillrule_string;
293 switch (fr)
294 {
295 case FillRule::EvenOdd: fillrule_string = "EVENODD"; break;
296 case FillRule::NonZero: fillrule_string = "NONZERO"; break;
297 case FillRule::Positive: fillrule_string = "POSITIVE"; break;
298 case FillRule::Negative: fillrule_string = "NEGATIVE"; break;
299 }
300
301 source << "CAPTION: " << last_test_no <<"." << endl;
302 source << "CLIPTYPE: " << cliptype_string << endl;
303 source << "FILLRULE: " << fillrule_string << endl;
304 source << "SOL_AREA: " << area << endl;
305 source << "SOL_COUNT: " << count << endl;
306 if (subj)

Callers 1

DoBenchmarkFunction · 0.85

Calls 7

BMH_SearchClass · 0.85
PathsToStreamFunction · 0.85
FindNextMethod · 0.80
LastFoundMethod · 0.80
FindNextEndLineMethod · 0.80
FileExistsFunction · 0.70
GetIntFunction · 0.70

Tested by

no test coverage detected