📄 playlist.cpp
字号:
/* playlist.cpp Playlist management class This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details, www.gnu.org. Copyright (C) 2000 Simon Harrison (email smh@N_O_S_P_A_M@dr.com)*/#include "playlist.h"CListItem::CListItem(char* value) { if (value) { int tlen = strlen(value); text = new char[tlen+1]; if (text) { strcpy( text,value ); len = tlen; } else { len=0; } } else { text = NULL; len = 0; } next = NULL; }CPlayList::Add( char* text ) { // add the text to the tail. CListItem* t = plist; if (plist) { while (t->GetNext()) t=t->GetNext(); t->SetNext( new CListItem( text ) ); } else { plist = new CListItem( text ); } changed = true; Entries++;}int CPlayList::ChopHead( ) { if (plist) { CListItem* t=plist->GetNext(); delete plist; plist = t; Entries--; changed = true; return 1; } else { return 0; }}CPlayList::DeleteAtIndex( int i ) { // zero based index. changed = true; if (i>=Entries) return 0; if (i) { SetPtrAtIndex( i-1 ); CListItem* t = ptemp->GetNext(); CListItem* next = t->GetNext(); delete t; ptemp->SetNext( next ); // repair the hole. } else { // special case for first item. CListItem* t=plist->GetNext(); delete plist; plist = t; } Entries--;}void CPlayList::Clean() //// Remove all entries from playlist.{ while (ChopHead()) {;}}CPlayList::DebugWriteOut() { CListItem* t = plist; if (plist) { int n=0; while (t) { printf( "Element %d : %s\n", n++, t->GetText() ); t=t->GetNext(); } } else { printf( "-- No elements in list. --\n" ); }}int CPlayList::ReadFromFile( char* fname )// Read full path names from file fname.{char buffer[1024];char* p; Clean(); FILE* fd = fopen( fname, "r" ); if (fd) { while (!feof(fd)) { buffer[0]=0; fgets( buffer, 1024, fd ); if (p = strrchr(buffer, '\n' )) { *p = 0; } if (buffer[0]) { Add(buffer); } } fclose( fd ); }}int CPlayList::WriteToFile( char* fname ){FILE* fd = fopen( fname, "w+" ); if (fd) { CListItem* t = plist; if (plist) { int n=0; while (t) { fprintf( fd, "%s\n", t->GetText() ); t=t->GetNext(); } } fclose( fd ); }}/*main () { CPlayList pl; pl.DebugWriteOut(); pl.Add( "boo" ); pl.Add( "boo hoo" ); pl.DebugWriteOut(); printf( "writing to file.\n" ); pl.WriteToFile( "filedump" ); pl.ReadFromFile( "filedump" ); pl.Add( "and this is the last one" ); pl.SetPtrAtIndex( 0 ); char* t="temp"; while (t) { t = pl.GetNext(); if (t) { printf( "Next is : %s\n", t ); } else { printf( "- End of list -\n" ); } }}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -