samedi 27 juin 2015

Creating a single binary or iso file block using static instantiation

I am working on a project, which includes a static single instantiation. The purpose is to create a binary or ISO file image, which enables users to transfer files into the image block size.

Here is the source code.

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
const long UNIQUENAMELIMIT = 100000;
long buff[UNIQUENAMELIMIT];

class CueSheetSingle
{
private:
    CueSheetSingle(){};

    CueSheetSingle(const CueSheetSingle&);

    const CueSheetSingle& operator=(const CueSheetSingle&);
    string BinFile;

public:
bool more(ifstream& is, int& n)
{
    if (is >> n) return true;
    else return false;
}

    bool copy(ofstream& os, ifstream& is, int& n)
{
    os << " " << n;
    return more(is, n);
}
    static CueSheetSingle& GetInstance()
   {
    static CueSheetSingle OnlyOneName;
        return OnlyOneName;
   }

    void SetAnotherFile(string BinaryFile)
   {
        BinFile = BinaryFile;
   }

   string GetAnotherFile()
   {
    return BinFile;

   }
   };

int main()
{
for (long j = 0; j < UNIQUENAMELIMIT; j++)
    buff[j] = j;

ofstream os("bdata.bin", ios::binary);

os.write(reinterpret_cast<char*>(buff), UNIQUENAMELIMIT*sizeof(long));
os.close();

ifstream is("bdata.bin", ios::binary);

is.read(reinterpret_cast<char*>(buff), UNIQUENAMELIMIT*sizeof(long));

for (long j = 0; j < UNIQUENAMELIMIT; j++)
if (buff[j] != j)
{
    cerr << "Data is incorrect\n"; return 1;
}

cout << "Data is correct\n";

CueSheetSingle& OnlyName = CueSheetSingle::GetInstance();
OnlyName.SetAnotherFile("Track01.mp3");

cout << "The name of the protected cue sheet is ";
cout << CueSheetSingle::GetInstance().GetAnotherFile();
    return 0;

}

I do hope that a good number of forum users should figure this one out. With plenty of teamwork from any of you, there should be a solution for this source code.

JohnDBCTZ

Aucun commentaire:

Enregistrer un commentaire