windows loading fix and streaming debug

This commit is contained in:
dave griffiths 2016-09-26 15:19:17 +01:00
parent 1b73a28f5b
commit f94db030b5
3 changed files with 70 additions and 112 deletions

View File

@ -315,8 +315,8 @@ ios &spiralcore::operator||(ios &s, sample &sa) {
ofstream *pos=dynamic_cast<ofstream*>(&s);
if (pos!=NULL) {
ofstream &os = *pos;
size_t len = sa.m_length;
os.write((char*)&len,sizeof(size_t));
u64 len = sa.m_length;
os.write((char*)&len,sizeof(u64));
os.write((char*)sa.m_data,sa.m_length*sizeof(audio_type));
return os;
}
@ -325,8 +325,8 @@ ios &spiralcore::operator||(ios &s, sample &sa) {
ifstream *pis=dynamic_cast<ifstream*>(&s);
assert(pis!=NULL);
ifstream &is = *pis;
size_t len=0;
is.read((char *)&len,sizeof(size_t));
u64 len=0;
is.read((char *)&len,sizeof(u64));
float *data = new float[len];
is.read((char*)data,len*sizeof(audio_type));
sa.m_data = data;

View File

@ -25,14 +25,15 @@ using namespace std;
template<>ios &spiralcore::operator||(ios &s, string &v) {
ofstream *pos=dynamic_cast<ofstream*>(&s);
if (pos!=NULL) {
#ifdef DEBUG_STREAM
cerr<<"streaming out string "<<v<<endl;
#endif
ofstream &os = *pos;
u64 len = v.length();
os.write((char *)&len,sizeof(u64));
os.write((char*)(v.c_str()),v.length());
return os;
}
else
{
} else {
ifstream *pis=dynamic_cast<ifstream*>(&s);
assert(pis!=NULL);
ifstream &is = *pis;
@ -44,66 +45,18 @@ template<>ios &spiralcore::operator||(ios &s, string &v) {
str[len]='\0';
v = string(str);
delete[] str;
}
else {
} else {
//v=string("");
}
#ifdef DEBUG_STREAM
cerr<<"streamed in string "<<v<<endl;
#endif
return is;
}
}
/*ios &operator||(ios &s, vector<U> &v) {
ofstream *pos=dynamic_cast<ofstream*>(&s);
if (pos!=NULL) {
ofstream &os = *pos;
size_t len = v.length();
os.write((char *)&len,sizeof(size_t));
return os.write((char*)(&v[0]),v.length()*sizeof(U));
}
else
{
ifstream *pis=dynamic_cast<ifstream*>(&s);
assert(pis);
ifstream &is = *pis;
size_t len=0;
is.read((char *)&len,sizeof(size_t));
v.reserve(len);
is.read((char*)&v[0],len);
return is;
}
}*/
/*
template<class U>ios &operator||(ios &s, vector<U> &v) {
ofstream *pos=dynamic_cast<ofstream*>(&s);
if (pos!=NULL) {
ofstream &os = *pos;
size_t len = v.length();
for (size_t i=0; i<len; ++i) {
os||v[i];
}
return os;
}
else
{
ifstream *pis=dynamic_cast<ifstream*>(&s);
assert(pis);
ifstream &is = *pis;
size_t len=0;
is.read((char *)&len,sizeof(size_t));
v.reserve(len);
for (size_t i=0; i<len; ++i) {
is||v[i];
}
return is;
}
}
*/
void spiralcore::stream_unit_test() {
ofstream of("test_data/streamtest.bin",ios::binary);

View File

@ -20,15 +20,27 @@
#include <list>
#include <assert.h>
#include <iostream>
#include "types.h"
#pragma once
//#define DEBUG_STREAM
#ifdef DEBUG_STREAM
#include <typeinfo>
#endif
namespace spiralcore {
// hack to do both stream directions in one function
// saw this years ago at computer artworks, not seen it since...
template<typename T>std::ios &operator||(std::ios &s, T &v) {
#ifdef DEBUG_STREAM
std::cerr<<"streaming a "<<typeid(v).name()<<std::endl;
#endif
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
if (pos!=NULL) {
std::ofstream &os = *pos;
@ -47,34 +59,18 @@ template<typename T>std::ios &operator||(std::ios &s, T &v) {
template<>std::ios &operator||(std::ios &s, std::string &v);
/*
template<typename T, typename U>T *stream_array(std::ios &s, T *v, U &len) {
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
if (pos!=NULL) {
std::ofstream &os = *pos;
os||len;
os.write((char*)v,sizeof(T)*len);
return v;
} else {
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
assert(pis);
std::ifstream &is = *pis;
is||len;
if (v!=NULL) delete[] v;
T* t = new T[len];
is.read((char *)t,sizeof(T)*len);
return t;
}
}
*/
template<typename T>std::ios &stream_vector(std::ios &s, std::vector<T> &v) {
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
#ifdef DEBUG_STREAM
std::cerr<<"streaming a vector "<<std::endl;
#endif
if (pos!=NULL) {
std::ofstream &os = *pos;
size_t len = v.size();
u64 len = v.size();
os||len;
for (size_t i=0; i<len; ++i) {
for (u64 i=0; i<len; ++i) {
os||v[i];
}
return os;
@ -84,11 +80,11 @@ template<typename T>std::ios &stream_vector(std::ios &s, std::vector<T> &v) {
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
assert(pis);
std::ifstream &is = *pis;
size_t len=0;
u64 len=0;
is||len;
//v.reserve(len);
v.clear();
for (size_t i=0; i<len; ++i) {
for (u64 i=0; i<len; ++i) {
T t;
is||t;
v.push_back(t);
@ -99,9 +95,12 @@ template<typename T>std::ios &stream_vector(std::ios &s, std::vector<T> &v) {
// skip a vector when loading
template<typename T>std::ios &skip_vector(std::ifstream &is) {
size_t len=0;
#ifdef DEBUG_STREAM
std::cerr<<"skipping a vector"<<std::endl;
#endif
u64 len=0;
is||len;
for (size_t i=0; i<len; ++i) {
for (u64 i=0; i<len; ++i) {
T t;
is||t;
}
@ -111,9 +110,12 @@ template<typename T>std::ios &skip_vector(std::ifstream &is) {
template<typename T>std::ios &stream_list(std::ios &s, std::list<T> &v) {
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
#ifdef DEBUG_STREAM
std::cerr<<"streaming a list"<<std::endl;
#endif
if (pos!=NULL) {
std::ofstream &os = *pos;
size_t len = v.size();
u64 len = v.size();
os||len;
for (typename std::list<T>::iterator i=v.begin(); i!=v.end(); ++i) {
os||*i;
@ -125,9 +127,9 @@ template<typename T>std::ios &stream_list(std::ios &s, std::list<T> &v) {
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
assert(pis);
std::ifstream &is = *pis;
size_t len=0;
u64 len=0;
is||len;
for (size_t i=0; i<len; ++i) {
for (u64 i=0; i<len; ++i) {
T t;
is||t;
v.push_back(t);
@ -137,9 +139,12 @@ template<typename T>std::ios &stream_list(std::ios &s, std::list<T> &v) {
}
template<typename T>std::ios &skip_list(std::istream &is) {
size_t len=0;
#ifdef DEBUG_STREAM
std::cerr<<"skipping a list"<<std::endl;
#endif
u64 len=0;
is||len;
for (size_t i=0; i<len; ++i) {
for (u64 i=0; i<len; ++i) {
T t;
is||t;
}