1 /* 2 Copyright (C) 2016 Apple Inc. All Rights Reserved. 3 See LICENSE.txt for this sample’s licensing information 4 5 Abstract: 6 Part of Core Audio AUInstrument Base Classes 7 */ 8 9 #include "SynthNoteList.h" 10 #include <stdexcept> 11 SanityCheck() const12void SynthNoteList::SanityCheck() const 13 { 14 if (mState >= kNoteState_Unset) { 15 throw std::runtime_error("SanityCheck: mState is bad"); 16 } 17 18 if (mHead == NULL) { 19 if (mTail != NULL) 20 throw std::runtime_error("SanityCheck: mHead is NULL but not mTail"); 21 return; 22 } 23 if (mTail == NULL) { 24 throw std::runtime_error("SanityCheck: mTail is NULL but not mHead"); 25 } 26 27 if (mHead->mPrev) { 28 throw std::runtime_error("SanityCheck: mHead has a mPrev"); 29 } 30 if (mTail->mNext) { 31 throw std::runtime_error("SanityCheck: mTail has a mNext"); 32 } 33 34 SynthNote *note = mHead; 35 while (note) 36 { 37 if (note->mState != mState) 38 throw std::runtime_error("SanityCheck: note in wrong state"); 39 if (note->mNext) { 40 if (note->mNext->mPrev != note) 41 throw std::runtime_error("SanityCheck: bad link 1"); 42 } else { 43 if (mTail != note) 44 throw std::runtime_error("SanityCheck: note->mNext is nil, but mTail != note"); 45 } 46 if (note->mPrev) { 47 if (note->mPrev->mNext != note) 48 throw std::runtime_error("SanityCheck: bad link 2"); 49 } else { 50 if (mHead != note) 51 throw std::runtime_error("SanityCheck: note->mPrev is nil, but mHead != note"); 52 } 53 note = note->mNext; 54 } 55 } 56