src/ldDocument.cpp

changeset 1065
c8ecddbd99e9
parent 1064
4c7a353cf583
child 1068
283de3bd8b0e
equal deleted inserted replaced
1064:4c7a353cf583 1065:c8ecddbd99e9
47 47
48 LDDocument::~LDDocument() 48 LDDocument::~LDDocument()
49 { 49 {
50 m_flags |= IsBeingDestroyed; 50 m_flags |= IsBeingDestroyed;
51 51
52 for (int i = 0; i < length(m_objects); ++i) 52 for (int i = 0; i < countof(m_objects); ++i)
53 m_objects[i]->destroy(); 53 m_objects[i]->destroy();
54 54
55 delete m_history; 55 delete m_history;
56 delete m_gldata; 56 delete m_gldata;
57 } 57 }
292 { 292 {
293 QByteArray subdata ((obj->asText() + "\r\n").toUtf8()); 293 QByteArray subdata ((obj->asText() + "\r\n").toUtf8());
294 data.append (subdata); 294 data.append (subdata);
295 295
296 if (sizeptr) 296 if (sizeptr)
297 *sizeptr += length(subdata); 297 *sizeptr += countof(subdata);
298 } 298 }
299 299
300 QFile f (path); 300 QFile f (path);
301 301
302 if (not f.open (QIODevice::WriteOnly)) 302 if (not f.open (QIODevice::WriteOnly))
324 324
325 // ============================================================================= 325 // =============================================================================
326 // 326 //
327 static void CheckTokenCount (const QStringList& tokens, int num) 327 static void CheckTokenCount (const QStringList& tokens, int num)
328 { 328 {
329 if (length(tokens) != num) 329 if (countof(tokens) != num)
330 throw QString (format ("Bad amount of tokens, expected %1, got %2", num, length(tokens))); 330 throw QString (format ("Bad amount of tokens, expected %1, got %2", num, countof(tokens)));
331 } 331 }
332 332
333 // ============================================================================= 333 // =============================================================================
334 // 334 //
335 static void CheckTokenNumbers (const QStringList& tokens, int min, int max) 335 static void CheckTokenNumbers (const QStringList& tokens, int min, int max)
393 { 393 {
394 try 394 try
395 { 395 {
396 QStringList tokens = line.split (" ", QString::SkipEmptyParts); 396 QStringList tokens = line.split (" ", QString::SkipEmptyParts);
397 397
398 if (length(tokens) <= 0) 398 if (countof(tokens) <= 0)
399 { 399 {
400 // Line was empty, or only consisted of whitespace 400 // Line was empty, or only consisted of whitespace
401 return LDSpawn<LDEmpty>(); 401 return LDSpawn<LDEmpty>();
402 } 402 }
403 403
404 if (length(tokens[0]) != 1 or not tokens[0][0].isDigit()) 404 if (countof(tokens[0]) != 1 or not tokens[0][0].isDigit())
405 throw QString ("Illogical line code"); 405 throw QString ("Illogical line code");
406 406
407 int num = tokens[0][0].digitValue(); 407 int num = tokens[0][0].digitValue();
408 408
409 switch (num) 409 switch (num)
413 // Comment 413 // Comment
414 QString commentText (line.mid (line.indexOf ("0") + 2)); 414 QString commentText (line.mid (line.indexOf ("0") + 2));
415 QString commentTextSimplified (commentText.simplified()); 415 QString commentTextSimplified (commentText.simplified());
416 416
417 // Handle BFC statements 417 // Handle BFC statements
418 if (length(tokens) > 2 and tokens[1] == "BFC") 418 if (countof(tokens) > 2 and tokens[1] == "BFC")
419 { 419 {
420 for (BfcStatement statement : iterateEnum<BfcStatement>()) 420 for (BfcStatement statement : iterateEnum<BfcStatement>())
421 { 421 {
422 if (commentTextSimplified == format("BFC %1", LDBfc::statementToString (statement))) 422 if (commentTextSimplified == format("BFC %1", LDBfc::statementToString (statement)))
423 return LDSpawn<LDBfc>(statement); 423 return LDSpawn<LDBfc>(statement);
432 return LDSpawn<LDBfc> (BfcStatement::Clip); 432 return LDSpawn<LDBfc> (BfcStatement::Clip);
433 else if (commentTextSimplified == "BFC CERTIFY NOCLIP") 433 else if (commentTextSimplified == "BFC CERTIFY NOCLIP")
434 return LDSpawn<LDBfc> (BfcStatement::NoClip); 434 return LDSpawn<LDBfc> (BfcStatement::NoClip);
435 } 435 }
436 436
437 if (length(tokens) > 2 and tokens[1] == "!LDFORGE") 437 if (countof(tokens) > 2 and tokens[1] == "!LDFORGE")
438 { 438 {
439 // Handle LDForge-specific types, they're embedded into comments too 439 // Handle LDForge-specific types, they're embedded into comments too
440 if (tokens[2] == "OVERLAY") 440 if (tokens[2] == "OVERLAY")
441 { 441 {
442 CheckTokenCount (tokens, 9); 442 CheckTokenCount (tokens, 9);
603 603
604 // ============================================================================= 604 // =============================================================================
605 // 605 //
606 int LDDocument::addObject (LDObject* obj) 606 int LDDocument::addObject (LDObject* obj)
607 { 607 {
608 history()->add (new AddHistoryEntry (length(objects()), obj)); 608 history()->add (new AddHistoryEntry (countof(objects()), obj));
609 m_objects << obj; 609 m_objects << obj;
610 addKnownVertices (obj); 610 addKnownVertices (obj);
611 obj->setDocument (this); 611 obj->setDocument (this);
612 setFlag(NeedsTriangleRecount); 612 setFlag(NeedsTriangleRecount);
613 m_window->renderer()->compileObject (obj); 613 m_window->renderer()->compileObject (obj);
681 681
682 // ============================================================================= 682 // =============================================================================
683 // 683 //
684 void LDDocument::setObjectAt (int idx, LDObject* obj) 684 void LDDocument::setObjectAt (int idx, LDObject* obj)
685 { 685 {
686 if (idx < 0 or idx >= length(m_objects)) 686 if (idx < 0 or idx >= countof(m_objects))
687 return; 687 return;
688 688
689 // Mark this change to history 689 // Mark this change to history
690 if (not m_history->isIgnoring()) 690 if (not m_history->isIgnoring())
691 { 691 {
706 706
707 // ============================================================================= 707 // =============================================================================
708 // 708 //
709 LDObject* LDDocument::getObject (int pos) const 709 LDObject* LDDocument::getObject (int pos) const
710 { 710 {
711 if (pos < length(m_objects)) 711 if (pos < countof(m_objects))
712 return m_objects[pos]; 712 return m_objects[pos];
713 else 713 else
714 return nullptr; 714 return nullptr;
715 } 715 }
716 716
717 // ============================================================================= 717 // =============================================================================
718 // 718 //
719 int LDDocument::getObjectCount() const 719 int LDDocument::getObjectCount() const
720 { 720 {
721 return length(objects()); 721 return countof(objects());
722 } 722 }
723 723
724 // ============================================================================= 724 // =============================================================================
725 // 725 //
726 bool LDDocument::hasUnsavedChanges() const 726 bool LDDocument::hasUnsavedChanges() const

mercurial