GED 2006 (C++)
File detail
Source code
/*
* File: image.h - abstract class Image
* Project: GED - bitmap editor (ICP)
* Author: Kamil Dudka, xdudka00
* Team: xdudka00, xfilak01, xhefka00, xhradi08
* Created: 2006-03-10
*/
#ifndef IMAGE_H
#define IMAGE_H
#include <string>
#include "framebuffer.h"
#include "command.h"
/**
* Abstract class Image
*/
class Image: public FrameBuffer, public CmdHistory {
public:
/**
* Read image from file and create Image object.
* \param szFileName Image file name.
* \return Pointer to Image object.
*/
static Image *readImageFromFile (const char *szFileName);
virtual ~Image() { }
/**
* Save image to desired file.
* \param fileName File name to save with.
*/
virtual void save (const std::string &fileName) = 0;
/**
* \return Return true if image is not from file
*/
bool bNew () const { return _bNewImage; }
/**
* \return Return image file name.
*/
std::string name () const { return _fileName; }
/**
* \return Return file pattern for fl_file_chooser dialog argument.
*/
std::string filePattern () const;
/**
* Set image name.
* \param name Desired name.
*/
void name (const std::string &name) { _fileName=name; }
/**
* Put command to history list and execute command.
* *pCmd object must by allocated on the heap and can never be destroyed. CmdHistory destroys it.
* \param pCmd Pointer to command.
* \return Reference to this. Needed for << operator concatenation.
*/
Image &operator<< (Cmd *pCmd) {
CmdHistory::operator<< (pCmd);
pCmd->exec();
return *this;
}
/**
* This is an exception thrown if image type is unknown.
* It can be also caused by bad file extension.
*/
class ErrUnknownFF { };
/**
* This is an exception thrown if image can't be opened.
*/
class ErrLoad { };
/**
* This is an exception thrown if image can't be saved.
*/
class ErrSave { };
protected:
/**
* Initialize base. Use AppWnd::newDocName() method to obtain image name.
* \param size Desired size of image.
*/
Image (const BoxSize &size);
/**
* Initialize base.
* \param fileName File name for new image.
*/
Image (const std::string &fileName): _fileName (fileName), _bNewImage (false) { }
private:
std::string _fileName; ///< Image file name
bool _bNewImage; ///< True if image is not from file.
};
/**
* Image using plugin for load/save.
*/
class PluginImage: public Image {
public:
/**
* Open image file using plugin.
* \param fileName Image file name.
* \param pluginName Plugin name to use.
*/
PluginImage (const std::string &fileName, const std::string pluginName);
/**
* Save image using plugin.
* \param fileName File name to save with.
*/
virtual void save (const std::string &fileName);
private:
std::string _strPluginName; ///< Plugin used to open image.
};
#endif