#include <string.h>
#include "CacheStream.h"
namespace
{
namespace
{
void
::
()
{
if
(
>
0
)
{
if
(
->
()!=
+
)
{
->
(
+
);
}
->
(
+
,
);
}
=
0
;
=
0
;
=
0
;
}
void
::
(
)
{
if
(
->
()!=
)
{
->
(
);
}
=
;
if
(
->
())
{
=
->
(
,
);
}
}
::
(
void
*
,
)
{
=
0
;
if
(
>=
&&
<
+
)
{
=(
)(
+
-
);
=
bufferMax
<
?
bufferMax
:
;
(
,
+(
-
),
min
);
readed
+=
min
;
=(
char
*)
+
min
;
}
if
(
>
readed
)
{
();
if
(
-
readed
>=
)
{
if
(
())
{
->
(
+
readed
);
}
=
->
(
,
-
readed
);
if
(
additional
!=-
1
)
{
readed
+=
additional
;
}
}
else
{
(
+
readed
);
=
-
readed
;
=
<
remain
?
:
remain
;
(
,
,
min
);
readed
+=
min
;
}
}
return
readed
;
}
::
(
void
*
,
)
{
=
0
;
if
(
>=
&&
<
+
)
{
=(
)(
+
-
);
=
bufferMax
<
?
bufferMax
:
;
=(
)(
-
);
(
+
writeStart
,
,
writeLength
);
written
+=
writeLength
;
=(
char
*)
+
writeLength
;
if
(
==
0
)
{
=
writeStart
;
=
writeLength
;
}
else
{
=
writeStart
+
writeLength
-
;
}
=
writeStart
+
writeLength
-
;
if
(
availableOffset
>
0
)
{
+=
availableOffset
;
}
}
if
(
>
written
)
{
();
if
(
-
written
>=
)
{
if
(
())
{
->
(
+
written
);
}
=
->
(
,
-
written
);
if
(
additional
!=-
1
)
{
written
+=
additional
;
}
}
else
{
(
+
written
);
=
-
written
;
(
,
,
);
written
+=
;
}
}
return
written
;
}
::
(
&
,
)
:target(&
)
,block(
)
,start(
0
)
,position(
0
)
,dirtyStart(
0
)
,dirtyLength(
0
)
,availableLength(
0
)
,operatedSize(
0
)
{
if
(
<=
0
)
{
=
65536
;
}
=
new
char
[
];
}
::
()
{
();
}
bool
::
()
const
{
return
!=
0
&&
->
();
}
bool
::
()
const
{
return
!=
0
&&
->
();
}
bool
::
()
const
{
return
!=
0
&&
->
();
}
bool
::
()
const
{
return
!=
0
&&
->
();
}
bool
::
()
const
{
return
!=
0
&&
->
();
}
bool
::
()
const
{
return
!=
0
&&
->
();
}
void
::
()
{
();
=
0
;
delete
[]
;
=
0
;
=-
1
;
=
0
;
=
0
;
=
0
;
=-
1
;
}
::
()
const
{
return
;
}
::
()
const
{
if
(
!=
0
)
{
if
(
())
{
return
->
();
}
else
{
return
;
}
}
else
{
return
-
1
;
}
}
void
::
(
)
{
(
+
);
}
void
::
(
)
{
if
(
())
{
if
(
<
0
)
{
=
0
;
}
else
if
(
>
())
{
=
();
}
else
{
=
;
}
}
}
void
::
(
)
{
(
()-
);
}
::
(
void
*
,
)
{
CHECK_ERROR(CanRead(), L"CacheStream::Read(void*, vint)#Stream is closed or operation not supported.");
do
{
if
(!(
()))
throw
(
L"CacheStream::Read(void*, vint)#Stream is closed or operation not supported."
);}
while
(
0
);
CHECK_ERROR(_size>=0, L"CacheStream::Read(void*, vint)#Argument size cannot be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"CacheStream::Read(void*, vint)#Argument size cannot be negative."
);}
while
(
0
);
=
(
,
);
+=
;
if
(
<
)
{
=
;
}
return
;
}
::
(
void
*
,
)
{
CHECK_ERROR(CanWrite(), L"CacheStream::Write(void*, vint)#Stream is closed or operation not supported.");
do
{
if
(!(
()))
throw
(
L"CacheStream::Write(void*, vint)#Stream is closed or operation not supported."
);}
while
(
0
);
CHECK_ERROR(_size>=0, L"CacheStream::Read(void*, vint)#Argument size cannot be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"CacheStream::Read(void*, vint)#Argument size cannot be negative."
);}
while
(
0
);
if
(
())
{
=
();
if
(
size
!=-
1
)
{
=(
)(
size
-(
+
));
if
(
remain
<
0
)
{
-=
remain
;
}
}
}
=
(
,
);
+=
;
if
(
<
)
{
=
;
}
return
;
}
::
(
void
*
,
)
{
CHECK_ERROR(CanPeek(), L"CacheStream::Peek(void*, vint)#Stream is closed or operation not supported.");
do
{
if
(!(
()))
throw
(
L"CacheStream::Peek(void*, vint)#Stream is closed or operation not supported."
);}
while
(
0
);
CHECK_ERROR(_size>=0, L"CacheStream::Read(void*, vint)#Argument size cannot be negative.");
do
{
if
(!(
>=
0
))
throw
(
L"CacheStream::Read(void*, vint)#Argument size cannot be negative."
);}
while
(
0
);
return
(
,
);
}
}
}