/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.0 (the "NPL"); you may not use this file except in
 * compliance with the NPL.  You may obtain a copy of the NPL at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the NPL is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
 * for the specific language governing rights and limitations under the
 * NPL.
 *
 * The Initial Developer of this code under the NPL is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 * Reserved.
 */
/*******************************************************************************
 * Source date: 9 Apr 1997 21:45:13 GMT
 * netscape/fonts/cstrm module C stub file
 * Generated by jmc version 1.8 -- DO NOT EDIT
 ******************************************************************************/

#include <stdlib.h>
#include <string.h>
#include "xp_mem.h"

/* Include the implementation-specific header: */
#include "Pcstrm.h"

/* Include other interface headers: */

/*******************************************************************************
 * cstrm Methods
 ******************************************************************************/

#ifndef OVERRIDE_cstrm_getInterface
JMC_PUBLIC_API(void*)
_cstrm_getInterface(struct cstrm* self, jint op, const JMCInterfaceID* iid, JMCException* *exc)
{
	if (memcmp(iid, &cstrm_ID, sizeof(JMCInterfaceID)) == 0)
		return cstrmImpl2cstrm(cstrm2cstrmImpl(self));
	return _cstrm_getBackwardCompatibleInterface(self, iid, exc);
}
#endif

#ifndef OVERRIDE_cstrm_addRef
JMC_PUBLIC_API(void)
_cstrm_addRef(struct cstrm* self, jint op, JMCException* *exc)
{
	cstrmImplHeader* impl = (cstrmImplHeader*)cstrm2cstrmImpl(self);
	impl->refcount++;
}
#endif

#ifndef OVERRIDE_cstrm_release
JMC_PUBLIC_API(void)
_cstrm_release(struct cstrm* self, jint op, JMCException* *exc)
{
	cstrmImplHeader* impl = (cstrmImplHeader*)cstrm2cstrmImpl(self);
	if (--impl->refcount == 0) {
		cstrm_finalize(self, exc);
	}
}
#endif

#ifndef OVERRIDE_cstrm_hashCode
JMC_PUBLIC_API(jint)
_cstrm_hashCode(struct cstrm* self, jint op, JMCException* *exc)
{
	return (jint)self;
}
#endif

#ifndef OVERRIDE_cstrm_equals
JMC_PUBLIC_API(jbool)
_cstrm_equals(struct cstrm* self, jint op, void* obj, JMCException* *exc)
{
	return self == obj;
}
#endif

#ifndef OVERRIDE_cstrm_clone
JMC_PUBLIC_API(void*)
_cstrm_clone(struct cstrm* self, jint op, JMCException* *exc)
{
	cstrmImpl* impl = cstrm2cstrmImpl(self);
	cstrmImpl* newImpl = (cstrmImpl*)malloc(sizeof(cstrmImpl));
	if (newImpl == NULL) return NULL;
	memcpy(newImpl, impl, sizeof(cstrmImpl));
	((cstrmImplHeader*)newImpl)->refcount = 1;
	return newImpl;
}
#endif

#ifndef OVERRIDE_cstrm_toString
JMC_PUBLIC_API(const char*)
_cstrm_toString(struct cstrm* self, jint op, JMCException* *exc)
{
	return NULL;
}
#endif

#ifndef OVERRIDE_cstrm_finalize
JMC_PUBLIC_API(void)
_cstrm_finalize(struct cstrm* self, jint op, JMCException* *exc)
{
	/* Override this method and add your own finalization here. */
	XP_FREEIF(self);
}
#endif

/*******************************************************************************
 * Jump Tables
 ******************************************************************************/

const struct cstrmInterface cstrmVtable = {
	_cstrm_getInterface,
	_cstrm_addRef,
	_cstrm_release,
	_cstrm_hashCode,
	_cstrm_equals,
	_cstrm_clone,
	_cstrm_toString,
	_cstrm_finalize,
	_cstrm_IsWriteReady,
	_cstrm_Write,
	_cstrm_Abort,
	_cstrm_Complete
};

/*******************************************************************************
 * Factory Operations
 ******************************************************************************/

JMC_PUBLIC_API(cstrm*)
cstrmFactory_Create(JMCException* *exception, struct nfrc* a, const char* b, const char* c)
{
	cstrmImplHeader* impl = (cstrmImplHeader*)XP_NEW_ZAP(cstrmImpl);
	cstrm* self;
	if (impl == NULL) {
		JMC_EXCEPTION(exception, JMCEXCEPTION_OUT_OF_MEMORY);
		return NULL;
	}
	self = cstrmImpl2cstrm(impl);
	impl->vtablecstrm = &cstrmVtable;
	impl->refcount = 1;
	_cstrm_init(self, exception, a, b, c);
	if (JMC_EXCEPTION_RETURNED(exception)) {
		XP_FREE(impl);
		return NULL;
	}
	return self;
}

