EbmlElement *EbmlMaster::AddNewElt(const EbmlCallbacks & Callbacks) { // add the element EbmlElement *NewElt = &EBML_INFO_CREATE(Callbacks); if (NewElt == NULL) return NULL; if (!PushElement(*NewElt)) { delete NewElt; NewElt = NULL; } return NewElt; }
bool kax_block_group_c::add_frame(const KaxTrackEntry &track, uint64 timecode, DataBuffer &buffer, int64_t past_block, int64_t forw_block, LacingType lacing) { KaxBlock & block = GetChild<KaxBlock>(*this); assert(NULL != ParentCluster); block.SetParent(*ParentCluster); ParentTrack = &track; bool result = block.AddFrame(track, timecode, buffer, lacing); kax_reference_block_c *past_ref = NULL; if (0 <= past_block) { past_ref = FindChild<kax_reference_block_c>(*this); if (NULL == past_ref) { past_ref = new kax_reference_block_c; PushElement(*past_ref); } past_ref->set_value(past_block); past_ref->SetParentBlock(*this); } if (0 <= forw_block) { kax_reference_block_c *forw_ref = FindChild<kax_reference_block_c>(*this); if (past_ref == forw_ref) { forw_ref = new kax_reference_block_c; PushElement(*forw_ref); } forw_ref->set_value(forw_block); forw_ref->SetParentBlock(*this); } return result; }
/*! \note Hopefully no global element is mandatory \todo should be called for ALL EbmlMaster element on construction */ bool EbmlMaster::ProcessMandatory() { if (EBML_CTX_SIZE(Context) == 0) { return true; } assert(Context.GetSize() != 0); unsigned int EltIdx; for (EltIdx = 0; EltIdx < EBML_CTX_SIZE(Context); EltIdx++) { if (EBML_CTX_IDX(Context,EltIdx).IsMandatory() && EBML_CTX_IDX(Context,EltIdx).IsUnique()) { // assert(EBML_CTX_IDX(Context,EltIdx).Create != NULL); PushElement(EBML_SEM_CREATE(EBML_CTX_IDX(Context,EltIdx))); } } return true; }
/*! \todo only return elements that are from the same type ! \todo the element might be the unique in the context ! */ EbmlElement *EbmlMaster::FindNextElt(const EbmlElement & PastElt, bool bCreateIfNull) { size_t Index; for (Index = 0; Index < ElementList.size(); Index++) { if ((ElementList[Index]) == &PastElt) { // found past element, new one is : Index++; break; } } while (Index < ElementList.size()) { if ((EbmlId)PastElt == (EbmlId)(*ElementList[Index])) break; Index++; } if (Index != ElementList.size()) return ElementList[Index]; if (bCreateIfNull) { // add the element EbmlElement *NewElt = &(PastElt.CreateElement()); if (NewElt == NULL) return NULL; if (!PushElement(*NewElt)) { delete NewElt; NewElt = NULL; } return NewElt; } return NULL; }
EbmlElement *EbmlMaster::FindFirstElt(const EbmlCallbacks & Callbacks, bool bCreateIfNull) { size_t Index; for (Index = 0; Index < ElementList.size(); Index++) { if (ElementList[Index] && EbmlId(*(ElementList[Index])) == EBML_INFO_ID(Callbacks)) return ElementList[Index]; } if (bCreateIfNull) { // add the element EbmlElement *NewElt = &EBML_INFO_CREATE(Callbacks); if (NewElt == NULL) return NULL; if (!PushElement(*NewElt)) { delete NewElt; NewElt = NULL; } return NewElt; } return NULL; }
int main(int argc, char * argv[]) { FILE * fin; /* file we'll be reading from */ char buffer[128]; /* read file into this buffer */ int line_count; /* current line count */ struct StkElement * stk_el; /* scratch stack element */ Stack * stk; /* the stack we will use */ char ch; /* character we're examing */ int i; /* for loop count */ if (argc != 2) { fprintf(stderr, "Usage: braces filename.ext\n"); exit(EXIT_FAILURE); } fin = fopen(argv[1], "rt"); if (fin == NULL) { fprintf(stderr, "Cannot open/find %s\n", argv[1]); exit(EXIT_FAILURE); } /* Create and initialize the stack */ stk = CreateStack(40); /* create a stack of 40 items */ if (stk == NULL) { fprintf(stderr, "Insufficient Memory\n"); exit(EXIT_FAILURE); } /* Create the scratch stack element */ stk_el = (struct StkElement *)malloc(sizeof(struct StkElement)); if (stk_el == NULL) { fprintf(stderr, "Insufficient memory\n"); exit(EXIT_FAILURE); } line_count = 0; while (!feof(fin)) { /* read a line of a C program */ if (fgets(buffer, 127, fin) == NULL) break; line_count += 1; /* scan and process braces, brackets, and parentheses */ for (i = 0; buffer[i] != '\0'; i++) { switch (ch = buffer[i]) { case '(': case '[': case '{': stk_el->opener = ch; stk_el->line_no = line_count; if (!PushElement(stk, stk_el)) { fprintf(stderr, "Out of stack space\n"); exit(EXIT_FAILURE); } break; case ')': case ']': case '}': if (!PopElement(stk, stk_el)) fprintf(stderr, "Stray %c at line %d\n", ch, line_count); else if ((ch == ')' && stk_el->opener != '(') || (ch == ']' && stk_el->opener != '[') || (ch == '}' && stk_el->opener != '{')) fprintf(stderr, "%c at line %d not matched by %c at line %d\n", ch, line_count, stk_el->opener, stk_el->line_no); break; default: continue; } } } /* we are at the end of file. Are there unmatched items? */ if (ViewElement(stk, 0) != NULL) while (PopElement(stk, stk_el) != 0) fprintf(stderr, "%c from line %d unmatched\n", stk_el->opener, stk_el->line_no); fprintf(stdout, "Error checking complete\n"); fclose(fin); return (EXIT_SUCCESS); }
/*! \todo only put the Blocks written in the cue entries */ filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bSaveDefault) { filepos_t Result = 0; size_t Index; EBML_MASTER_ITERATOR TrkItr, Itr; // update the Timecode of the Cluster before writing KaxClusterTimecode * Timecode = static_cast<KaxClusterTimecode *>(this->FindElt(EBML_INFO(KaxClusterTimecode))); *static_cast<EbmlUInteger *>(Timecode) = GlobalTimecode() / GlobalTimecodeScale(); if (Blobs.size() == 0) { // old-school direct KaxBlockGroup // SilentTracks handling // check the parent cluster for existing tracks and see if they are contained in this cluster or not if (bSilentTracksUsed) { KaxTracks & MyTracks = *static_cast<KaxTracks *>(ParentSegment->FindElt(EBML_INFO(KaxTracks))); for (TrkItr = MyTracks.begin(); TrkItr != MyTracks.end(); ++TrkItr) { if (EbmlId(*(*TrkItr)) == EBML_ID(KaxTrackEntry)) { KaxTrackEntry & entry = *static_cast<KaxTrackEntry *>(*TrkItr); uint32 tracknum = entry.TrackNumber(); for (Itr = begin(); Itr != end(); ++Itr) { if (EbmlId(*(*Itr)) == EBML_ID(KaxBlockGroup)) { KaxBlockGroup & group = *static_cast<KaxBlockGroup *>(*Itr); if (group.TrackNumber() == tracknum) break; // this track is used } } // the track wasn't found in this cluster if (Itr == end()) { KaxClusterSilentTracks * SilentTracks = static_cast<KaxClusterSilentTracks *>(this->FindFirstElt(EBML_INFO(KaxClusterSilentTracks))); assert(SilentTracks != NULL); // the flag bSilentTracksUsed should be set when creating the Cluster KaxClusterSilentTrackNumber * trackelt = static_cast<KaxClusterSilentTrackNumber *>(SilentTracks->AddNewElt(EBML_INFO(KaxClusterSilentTrackNumber))); *static_cast<EbmlUInteger *>(trackelt) = tracknum; } } } } Result = EbmlMaster::Render(output, bSaveDefault); // For all Blocks add their position on the CueEntry for (Itr = begin(); Itr != end(); ++Itr) { if (EbmlId(*(*Itr)) == EBML_ID(KaxBlockGroup)) { CueToUpdate.PositionSet(*static_cast<const KaxBlockGroup *>(*Itr)); } } } else { // new school, using KaxBlockBlob for (Index = 0; Index<Blobs.size(); Index++) { #if MATROSKA_VERSION >= 2 if (Blobs[Index]->IsSimpleBlock()) PushElement( (KaxSimpleBlock&) *Blobs[Index] ); else #endif PushElement( (KaxBlockGroup&) *Blobs[Index] ); } // SilentTracks handling // check the parent cluster for existing tracks and see if they are contained in this cluster or not if (bSilentTracksUsed) { KaxTracks & MyTracks = *static_cast<KaxTracks *>(ParentSegment->FindElt(EBML_INFO(KaxTracks))); for (TrkItr = MyTracks.begin(); TrkItr != MyTracks.end(); ++TrkItr) { if (EbmlId(*(*TrkItr)) == EBML_ID(KaxTrackEntry)) { KaxTrackEntry & entry = *static_cast<KaxTrackEntry *>(*TrkItr); uint32 tracknum = entry.TrackNumber(); for (Index = 0; Index<Blobs.size(); Index++) { if (((KaxInternalBlock&)*Blobs[Index]).TrackNum() == tracknum) break; // this track is used } // the track wasn't found in this cluster if (Index == ListSize()) { KaxClusterSilentTracks * SilentTracks = static_cast<KaxClusterSilentTracks *>(this->FindFirstElt(EBML_INFO(KaxClusterSilentTracks))); assert(SilentTracks != NULL); // the flag bSilentTracksUsed should be set when creating the Cluster KaxClusterSilentTrackNumber * trackelt = static_cast<KaxClusterSilentTrackNumber *>(SilentTracks->AddNewElt(EBML_INFO(KaxClusterSilentTrackNumber))); *static_cast<EbmlUInteger *>(trackelt) = tracknum; } } } } Result = EbmlMaster::Render(output, bSaveDefault); // For all Blocks add their position on the CueEntry for (Index = 0; Index<Blobs.size(); Index++) { CueToUpdate.PositionSet(*Blobs[Index]); } Blobs.clear(); } return Result; }
int main() { ListNode* head = NULL; PushElement( &head, 3); ListNode *temp = head; int i = 0; for( i = 0; i < 500; i++ ) { PushElement( &head->next, i % 20 ); head = head->next; } head = temp; #if 0 PushElement( &head, 3); PushElement( &(head->next), 2 ); PushElement( &(head->next->next), 2 ); PushElement( &(head->next->next->next), 1 ); PushElement( &(head->next->next->next->next, 3); PushElement( &(head->next->next->next->next->next), 2 ); PushElement( &(head->next->next->next->next->next->next), 2 ); PushElement( &(head->next->next->next->next->next->next), 1 ); PushElement( &head, 3); PushElement( &(head->next), 2 ); PushElement( &(head->next->next), 2 ); PushElement( &(head->next->next->next), 1 ); // PushElement( &(head->next->next->next->next), 1 ); #endif // Sort the linked list. MergeSortOnLL( &head ); PrintList( head ); RemoveDuplicatesFromList( head ); PrintList( head ); }