VIZ++ Class: JPGFile

 VIZ++ Class Library  VIZ++ Samples  VIZ++ ClassTree 

Source code

/*
 * JPGFile.h 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



#pragma once

#include <viz++/Object.h>
#include <viz++/Exception.h>
#include <jpeglib.h>

#pragma comment(lib, "jpeg.lib")

namespace VIZ {

class JPGFile :public Object {
protected:
  typedef enum {
    READER = 0,
    WRITER = 1,
  } OPERATION;

private:
  FILE* fp;
  OPERATION operation;

private:
  JPGFile()
  {
  }

protected:
  JPGFile(OPERATION operation,const char* filename)
  :fp(NULL),
  operation(operation)
  {
    if (filename == NULL) {
      throw IException("Invalid argument");
    }
    static const char* mode[] =  { "rb", "wb" };

    errno_t err = fopen_s(&fp, filename, mode[operation]);
    if (err != 0) {
      throw IException("Failed to open %s", filename);
    }
  }

  ~JPGFile()
  {
    close();
  }

  FILE* getFP()
  {
    return fp;
  }
  
  void close()
  {
    if (fp) {
     fclose(fp);
     fp = NULL;
    }
  }
  
};

}
 

Last modified: 10 Feb 2017

Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.