Remove old ByteArray CPP class

This commit is contained in:
Joshua Granick
2015-12-31 14:41:54 -08:00
parent f319a56b65
commit 4dc0aa3db4
3 changed files with 0 additions and 311 deletions

View File

@@ -82,15 +82,12 @@ which is available under an "MIT" license. For details, see
https://github.com/haxenme/nme
legacy/
lime/utils/ByteArray.hx
lime/utils/JNI.hx
project/include/utils/ByteArray.h
project/include/utils/QuickVec.h
project/src/graphics/format/
project/src/graphics/opengl/
project/src/system/JNI.cpp
project/src/text/Font.cpp
project/src/utils/ByteArray.cpp
project/src/utils/LZMA.cpp
tools/utils/JavaExternGenerator.hx

View File

@@ -1,93 +0,0 @@
#ifndef LIME_UTILS_BYTE_ARRAY_H
#define LIME_UTILS_BYTE_ARRAY_H
#include <utils/Object.h>
#include <utils/QuickVec.h>
#include <stdio.h>
namespace lime {
typedef unsigned char uint8;
/*#if HX_WINDOWS
typedef wchar_t OSChar;
#define val_os_string val_wstring
#else*/
typedef char OSChar;
#define val_os_string val_string
//#endif
// If you put this structure on the stack, then you do not have to worry about GC.
// If you store this in a heap structure, then you will need to use GC roots for mValue...
struct ByteArray {
ByteArray (int inSize);
ByteArray (const ByteArray &inRHS);
ByteArray ();
ByteArray (struct _value *Value);
ByteArray (const QuickVec<unsigned char> &inValue);
ByteArray (const OSChar *inFilename);
void Resize (int inSize);
int Size() const;
unsigned char *Bytes ();
const unsigned char *Bytes () const;
bool Ok () { return mValue != 0; }
struct _value *mValue;
static int ToFile (const OSChar *inFilename, const ByteArray array);
};
#ifdef ANDROID
ByteArray AndroidGetAssetBytes(const char *);
struct FileInfo
{
int fd;
off_t offset;
off_t length;
};
FileInfo AndroidGetAssetFD(const char *);
#endif
/*#ifdef HX_WINDOWS
typedef wchar_t OSChar;
#define val_os_string val_wstring
#define OpenRead(x) _wfopen(x,L"rb")
#define OpenOverwrite(x) _wfopen(x,L"wb") // [ddc]
#else*/
//typedef char OSChar;
//#define val_os_string val_string
#if defined(IPHONE)
extern int gFixedOrientation;
#elif defined(HX_MACOS)
#else
#ifdef TIZEN
extern int gFixedOrientation;
#endif
#endif
//#endif
}
#endif

View File

@@ -1,215 +0,0 @@
#include <hx/CFFI.h>
#include <system/System.h>
#include <utils/ByteArray.h>
#include <string>
namespace lime {
AutoGCRoot *gByteArrayCreate = 0;
AutoGCRoot *gByteArrayLen = 0;
AutoGCRoot *gByteArrayResize = 0;
AutoGCRoot *gByteArrayBytes = 0;
ByteArray::ByteArray (int inSize) {
mValue = val_call1 (gByteArrayCreate->get (), alloc_int (inSize));
}
ByteArray::ByteArray () : mValue(0) {
}
ByteArray::ByteArray (const QuickVec<uint8> &inData) {
mValue = val_call1 (gByteArrayCreate->get (), alloc_int (inData.size ()));
uint8 *bytes = Bytes ();
if (bytes)
memcpy (bytes, &inData[0], inData.size ());
}
ByteArray::ByteArray (const ByteArray &inRHS) : mValue (inRHS.mValue) {
}
ByteArray::ByteArray (value inValue) : mValue (inValue) {
}
ByteArray::ByteArray (const OSChar *inFilename) {
FILE_HANDLE *file = lime::fopen (inFilename, "rb");
if (!file) {
//#ifdef ANDROID
//return AndroidGetAssetBytes(inFilename);
//#endif
return;
}
lime::fseek (file, 0, SEEK_END);
int len = lime::ftell (file);
lime::fseek (file, 0, SEEK_SET);
mValue = val_call1 (gByteArrayCreate->get (), alloc_int (len));
int status = lime::fread (Bytes (), len, 1, file);
lime::fclose (file);
}
void ByteArray::Resize (int inSize) {
if (mValue == 0)
mValue = val_call1 (gByteArrayCreate->get (), alloc_int (inSize));
else
val_call2 (gByteArrayResize->get (), mValue, alloc_int (inSize));
}
int ByteArray::Size () const {
return val_int (val_call1 (gByteArrayLen->get (), mValue));
}
const unsigned char *ByteArray::Bytes () const {
value bytes = val_call1 (gByteArrayBytes->get (), mValue);
if (val_is_string (bytes))
return (unsigned char *)val_string (bytes);
buffer buf = val_to_buffer (bytes);
if (buf == 0) {
val_throw (alloc_string ("Bad ByteArray"));
}
return (unsigned char *)buffer_data (buf);
}
unsigned char *ByteArray::Bytes () {
value bytes = val_call1 (gByteArrayBytes->get (),mValue);
if (val_is_string (bytes))
return (unsigned char *)val_string (bytes);
buffer buf = val_to_buffer (bytes);
if (buf == 0) {
val_throw (alloc_string ("Bad ByteArray"));
}
return (unsigned char *)buffer_data (buf);
}
value lime_byte_array_get_native_pointer (value inByteArray) {
ByteArray bytes (inByteArray);
if (!val_is_null (bytes.mValue)) {
return alloc_float ((intptr_t)bytes.Bytes ());
}
return alloc_null ();
}
value lime_byte_array_init (value inFactory, value inLen, value inResize, value inBytes) {
gByteArrayCreate = new AutoGCRoot (inFactory);
gByteArrayLen = new AutoGCRoot (inLen);
gByteArrayResize = new AutoGCRoot (inResize);
gByteArrayBytes = new AutoGCRoot (inBytes);
return alloc_null ();
}
value lime_byte_array_overwrite_file (value inFilename, value inBytes) {
// file is created if it doesn't exist,
// if it exists, it is truncated to zero
FILE_HANDLE *file = lime::fopen (val_os_string (inFilename), "wb");
if (!file) {
#ifdef ANDROID
// [todo]
#endif
return alloc_null();
}
ByteArray array (inBytes);
// The function fwrite() writes nitems objects, each size bytes long, to the
// stream pointed to by stream, obtaining them from the location given by
// ptr.
// fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);
lime::fwrite (array.Bytes (), 1, array.Size (), file);
lime::fclose (file);
return alloc_null ();
}
value lime_byte_array_read_file (value inFilename) {
ByteArray result = ByteArray (val_os_string(inFilename));
return result.mValue;
}
DEFINE_PRIM (lime_byte_array_get_native_pointer, 1);
DEFINE_PRIM (lime_byte_array_init, 4);
DEFINE_PRIM (lime_byte_array_overwrite_file, 2);
DEFINE_PRIM (lime_byte_array_read_file, 1);
}
extern "C" int lime_byte_array_register_prims () {
return 0;
}