uristream.cpp revision d2b58ce026acede18e29bfa0d8046193bbe7d754
/**
* Our base String stream classes. We implement these to
* be based on Glib::ustring
*
* Authors:
* Bob Jamison <rjamison@titan.com>
*
* Copyright (C) 2004 Inkscape.org
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "uristream.h"
#include "sys.h"
#ifdef WIN32
// For now to get at is_os_wide().
#endif
namespace Inkscape
{
namespace IO
{
/*
* URI scheme types
*/
#define SCHEME_NONE 0
#define SCHEME_FILE 1
#define SCHEME_DATA 2
/*
* A temporary modification of Jon Cruz's portable fopen().
* Simplified a bit, since we will always use binary
*/
#define FILE_READ 1
#define FILE_WRITE 2
{
if (!utf8name)
{
return NULL;
}
{
return NULL;
}
#ifndef WIN32
if ( filename ) {
else
}
#else
if ( PrintWin32::is_os_wide() ) {
if ( wideName ) {
else
} else {
}
} else {
if ( filename ) {
else
}
}
#endif
return fp;
}
//#########################################################################
//# U R I I N P U T S T R E A M / R E A D E R
//#########################################################################
/**
*
*/
{
//get information from uri
//printf("in schemestr:'%s' scheme:'%d'\n", schemestr, scheme);
switch (scheme) {
case SCHEME_FILE:
//printf("in cpath:'%s'\n", cpath);
//inf = fopen(cpath, "rb");
if (!inf) {
throw StreamException(err);
}
break;
case SCHEME_DATA:
//printf("in data:'%s'\n", data);
dataPos = 0;
break;
}
closed = false;
}
/**
*
*/
{
if (!inf) {
throw StreamException(err);
}
closed = false;
}
/**
*
*/
{
close();
}
/**
* Returns the number of bytes that can be read (or skipped over) from
* this input stream without blocking by the next caller of a method for
* this input stream.
*/
{
return 0;
}
/**
* Closes this input stream and releases any system resources
* associated with the stream.
*/
{
if (closed)
return;
switch (scheme) {
case SCHEME_FILE:
if (!inf)
return;
break;
case SCHEME_DATA:
//do nothing
break;
}//switch
closed = true;
}
/**
* Reads the next byte of data from the input stream. -1 if EOF
*/
{
int retVal = -1;
if (!closed)
{
switch (scheme) {
case SCHEME_FILE:
{
retVal = -1;
}
else
{
}
break;
case SCHEME_DATA:
{
retVal = -1;
}
else
{
}
break;
}//switch
}
return retVal;
}
/**
*
*/
throw (StreamException)
{
}
/**
*
*/
{
delete inputStream;
}
/**
*
*/
{
return inputStream->available();
}
/**
*
*/
{
inputStream->close();
}
/**
*
*/
{
return ch;
}
//#########################################################################
//# U R I O U T P U T S T R E A M / W R I T E R
//#########################################################################
/**
* Temporary kludge
*/
throw (StreamException): closed(false),
ownsFile(false),
{
if (!outf) {
throw StreamException(err);
}
}
/**
*
*/
throw (StreamException): closed(false),
ownsFile(true),
{
//get information from uri
//printf("out schemestr:'%s' scheme:'%d'\n", schemestr, scheme);
switch (scheme) {
case SCHEME_FILE:
//printf("out path:'%s'\n", cpath);
//outf = fopen(cpath, "wb");
if (!outf) {
throw StreamException(err);
}
break;
case SCHEME_DATA:
data = "data:";
break;
}//switch
}
/**
*
*/
{
close();
}
/**
* Closes this output stream and releases any system resources
* associated with this stream.
*/
{
if (closed)
return;
switch (scheme) {
case SCHEME_FILE:
if (!outf)
return;
if ( ownsFile )
break;
case SCHEME_DATA:
break;
}//switch
closed = true;
}
/**
* Flushes this output stream and forces any buffered output
* bytes to be written out.
*/
{
if (closed)
return;
switch (scheme) {
case SCHEME_FILE:
if (!outf)
return;
break;
case SCHEME_DATA:
//nothing
break;
}//switch
}
/**
* Writes the specified byte to this output stream.
*/
{
if (closed)
return;
unsigned char uch;
switch (scheme) {
case SCHEME_FILE:
if (!outf)
return;
//fwrite(uch, 1, 1, outf);
break;
case SCHEME_DATA:
break;
}//switch
}
/**
*
*/
throw (StreamException)
{
}
/**
*
*/
{
delete outputStream;
}
/**
*
*/
{
outputStream->close();
}
/**
*
*/
{
outputStream->flush();
}
/**
*
*/
{
}
} // namespace IO
} // namespace Inkscape
//#########################################################################
//# E N D O F F I L E
//#########################################################################