OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
filedoc.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of classes TFileDocument, TFileInStream, TFileOutStream,
7/// TFileBuf
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/filedoc.h>
11#include <stdio.h>
12
14
15using namespace std;
16
17namespace owl {
18
20
21
22//
23// class TFileBuf
24// ~~~~~ ~~~~~~~~
25class _OWLCLASS TFileBuf : public tstreambuf {
26 bool buffered_;
27 tchar *base_;
28 tchar *ebuf_;
29 public:
30 enum { shDefault = shReadWrite }; // default file sharing
31
32 ~TFileBuf() {
33 if (base_) delete[] base_;
34 }
35 int_type eof(){
36 return traits_type::eof();
37 }
38 TFileBuf(int fhdl, int omode, streampos seekpos);
39
40
41 virtual int_type overflow(int_type c = tstreambuf::traits_type::eof());
42 virtual int_type underflow();
43
44 virtual tstreambuf* setbuf(char_type *s, streamsize n);
45
46 virtual pos_type seekoff(off_type,
47 ios_base::seekdir, ios_base::openmode which =
48 ios_base::in | ios_base::out);
49
50 virtual pos_type seekpos(pos_type sp,
51 ios_base::openmode which =
52 ios_base::in | ios_base::out);
53
54 virtual int sync();
55
56 int out_waiting(){
57 return pptr() ? static_cast<int>(pptr() - pbase()) : 0;
58 }
59
60 void setb(tchar* beg, tchar* end, int = 0){
61 streamsize size_buf = end - beg;
62 buffered_ = beg && size_buf;
63 setbuf(beg, size_buf);
64 }
65
66 int unbuffered(){
67 return !buffered_;
68 }
69
70 void unbuffered(int buf){
71 if (buf){
72 buffered_ = false;
73 setb(nullptr, nullptr, 0);
74 }
75 }
76
77 tchar *base(){
78 return base_;
79 }
80
81 int blen(){
82 return static_cast<int> (ebuf_ - base_);
83 }
84
85 int xfd; // the file descriptor, EOF if closed
86 int mode; // the opened mode
87 streampos last_seek;
88 tchar lahead[2]; // current input char if unbuffered
89};
90
91//
92// class TFileStreamBase
93// ~~~~~ ~~~~~~~~~~~~~~~
94//
95class _OWLCLASS TFileStreamBase : virtual public tios {
96 public:
97 TFileStreamBase(int fhdl, int omode, streampos seekpos);
98 ~TFileStreamBase() {}
99 TFileBuf buf;
100};
101
102//
103// class TFileInStream
104// ~~~~~ ~~~~~~~~~~~~~
105//JJH gcc-3.1 doesn't like original inheritance order - it refuses to
106// correctly fill rdbuf variable - effect is that you cannot save
107// anything... (all this just becaus of MI!).
108#if (__GNUC__ >= 3)
109class _OWLCLASS TFileInStream : public TInStream, public TFileStreamBase {
110#else
111class _OWLCLASS TFileInStream : public TFileStreamBase, public TInStream {
112#endif
113 public:
114 TFileInStream(TFileDocument& doc, HFILE fhdl, int omode, streampos seekpos)
115 : TFileStreamBase{fhdl, omode, seekpos}, TInStream{doc, nullptr, omode} {}
116 ~TFileInStream();
117};
118
119//
120// class TFileOutStream
121// ~~~~~ ~~~~~~~~~~~~~~
122//JJH the same as above, you have to change inheritance order in order
123// TFileOutStream to work correctly...
124#if (__GNUC__ >= 3)
125class _OWLCLASS TFileOutStream : public TOutStream, public TFileStreamBase {
126#else
127class _OWLCLASS TFileOutStream : public TFileStreamBase, public TOutStream {
128#endif
129 public:
130 TFileOutStream(TFileDocument& doc, HFILE fhdl, int omode, streampos seekpos)
131 : TFileStreamBase{fhdl,omode,seekpos}, TOutStream{doc, nullptr, omode} {}
132 ~TFileOutStream();
133};
134
135
136//------------------------------------------------------------------------------
137
138//
139/// Opens the file document after checking the file sharing mode (omode). If a file
140/// mode is not specified as read, write, or read and write, OpenThisFile returns 0.
141//
142/// \todo This method uses obsolete WinApi functions for 16-bit compatibility
143/// which is no longer supported
144HFILE
145TFileDocument::OpenThisFile(int omode, const tstring& fileName, streampos* pseekpos)
146{
147 int how;
148 HFILE fhdl;
149 bool exists = false;
150 int share = omode & shMask;
152 const auto fn = _W2A(fileName.c_str());
153
154 if (share < shCompat)
156
157 how = (static_cast<unsigned>(share-shCompat)) >> 5;
158
159 if (omode & ofWrite) {
160 if (!(omode & (ofAtEnd | ofAppend | ofRead)))
161 omode |= ofTruncate; // output implies truncate unless in, app, or ate
162
163 if (omode & ofRead)
164 how |= OF_READWRITE;
165 else
166 how |= OF_WRITE;
167 if (!((omode & ofNoCreate) && !(omode & ofTruncate))) {
168 if (!((omode & ofTruncate) && !(omode & (ofNoCreate | ofNoReplace)))) {
172 exists = true;
173 }
174 }
175 if (!(exists && !(omode & (ofNoCreate | ofNoReplace)))) {
176 if ((exists && (omode & ofNoReplace))
177 || (!exists && (omode & ofNoCreate)) )
178// return 0; // ? Jogy - this function should return either valid handle or HFILE_ERROR
179 return HFILE_ERROR;
180 if ((fhdl = _lcreat(fn, 0)) == HFILE_ERROR)
181 return HFILE_ERROR;
182 ::_lclose(fhdl); // close in order to open with share mode
183 }
184 }
185 }
186 else if (omode & ofRead)
187 how |= OF_READ;
188 else
189 return HFILE_ERROR; // must specfify in, out, or in/out
190
191 if ((fhdl = ::_lopen(fn, how)) != HFILE_ERROR) {
192 if ((*pseekpos = ::_llseek(fhdl, 0, (omode & (ofAtEnd|ofAppend))
195 return HFILE_ERROR;
196 }
197 }
198 const HANDLE f = reinterpret_cast<HANDLE>(static_cast<INT_PTR>(fhdl));
199 FileLength = GetFileSize(f, nullptr);
200 InfoPresent = GetFileTime(f, &FileCreateTime, &FileAccessTime, &FileUpdateTime);
201
202 NotifyViews(vnDocOpened,omode);
203 return fhdl;
204}
205
206
207//
208/// Closes the file handle if the associated file was opened by TFileDocument. Calls
209/// TDocument::NotifyViews() to notify all views that the file document has closed.
210//
211void
212TFileDocument::CloseThisFile(HFILE fhdl, int omode)
213{
214 if (!IS_PREV_OPEN(omode)) {
216 NotifyViews(vnDocClosed, omode);
217 }
218}
219
220//
221/// Overrides TDocument::Open and opens the file using the specified path. If the
222/// file is already open, returns 0. Calls TDocument::SetDocPath to set the
223/// directory path. If mode is not 0, sets TDocument::OpenMode to mode. If the file
224/// cannot be opened, returns 0.
225//
226bool
227TFileDocument::Open(int omode, LPCTSTR path)
228{
229 if (FHdl != HFILE_ERROR)
230 return false; // if already open at document level
231
232 if (path)
233 SetDocPath(path);
234 if (omode != 0)
235 SetOpenMode(omode);
236
237 streampos seekpos;
238 if ((FHdl = OpenThisFile(GetOpenMode(),GetDocPath(),&seekpos)) == HFILE_ERROR)
239 return false;
240 return true;
241}
242
243//
244/// Opens a file document using an existing file handle. Sets TDocument::OpenMode to
245/// PREV_OPEN and read/write. Sets the document path to 0. Sets FHdl to fhdl. Always
246/// returns a nonzero value.
247//
248bool
249TFileDocument::Open(HFILE fhdl)
250{
251 SetOpenMode(PREV_OPEN | ofReadWrite); // !CQ can we determine open mode?
252 SetDocPath(nullptr); // !CQ can we get path name?
253 FHdl = fhdl;
254 return true;
255}
256
257//
258/// Closes the document but does not delete or detach any associated views. Before
259/// closing the document, Close calls TDocument::Close to make sure all child
260/// documents are closed. If any children are open, Close returns 0 and does not
261/// close the document. If all children are closed, Close checks to see if any
262/// associated streams are open, and if so, returns 0 and does not close the
263/// document. If there are no open streams, Close closes the file.
264//
265bool
266TFileDocument::Close()
267{
268 if (!TDocument::Close()) // close all children first
269 return false;
270 if (FHdl != HFILE_ERROR) { // if open at document level
271 if (TDocument::IsOpen()) // cannot close document if streams open
272 return false; // ?should we close streams here?
273 CloseThisFile(FHdl, GetOpenMode());
274 FHdl = HFILE_ERROR;
275 }
276 return true;
277}
278
279//
280/// Calls TDocument::Commit and clears TDocument's DirtyFlag data member, thus
281/// indicating that there are no unsaved changes made to the document.
282//
283bool
284TFileDocument::Commit(bool force)
285{
286 if (!TDocument::Commit(force)) // flush views and child docs
287 return false;
288 SetDirty(false);
289 return true;
290}
291
292//
293/// Calls TDocument::Revert to notify the views to refresh their data. If clear is
294/// false, the data is restored instead of cleared.
295//
296bool
297TFileDocument::Revert(bool clear)
298{
299 if (!TDocument::Revert(clear))
300 return false;
301 SetDirty(false);
302 return true;
303}
304
305static LPCTSTR PropNames[] = {
306 _T("Create Time"), // CreateTime
307 _T("Modify Time"), // ModifyTime
308 _T("Access Time"), // AccessTime
309 _T("Storage Size"), // StorageSize
310 _T("File Handle"), // FileHandle
311};
312
313static int PropFlags[] = {
314 pfGetBinary|pfGetText, // CreateTime
315 pfGetBinary|pfGetText, // ModifyTime
316 pfGetBinary|pfGetText, // AccessTime
317 pfGetBinary|pfGetText, // StorageSize
318 pfGetBinary, // FileHandle
319};
320
321//
322/// Returns the text name of the property given the index value.
323//
325TFileDocument::PropertyName(int index)
326{
327 if (index <= PrevProperty)
328 return TDocument::PropertyName(index);
329 else if (index < NextProperty)
330 return PropNames[index-PrevProperty-1];
331 else
332 return nullptr;
333}
334
335//
336/// Returns the property attribute constants (pfGetText, pfHidden, and so on).
337//
338int
339TFileDocument::PropertyFlags(int index)
340{
341 if (index <= PrevProperty)
342 return TDocument::PropertyFlags(index);
343 else if (index < NextProperty)
344 return PropFlags[index-PrevProperty-1];
345 else
346 return 0;
347}
348
349//
350/// Gets the property index, given the property name (name). Returns 0 if the name
351/// is not found.
352//
353int
354TFileDocument::FindProperty(LPCTSTR name)
355{
356 int i;
357 for (i=0; i < NextProperty-PrevProperty-1; i++)
358 if (_tcscmp(PropNames[i], name) == 0)
359 return i+PrevProperty+1;
360 return TDocument::FindProperty(name);
361}
362
363//
364/// Overrides TDocument::GetProperty.
365/// \sa TFileDocument::TFileDocProp
366//
367int
368TFileDocument::GetProperty(int index, void * dest, int textlen)
369{
370 // Formats a file date + time string.
371 //
372 const auto formatFileTime = [](const FILETIME& pft, void* dest, int textlen) -> int
373 {
374 tchar buf[40];
375 int len;
376
377 if (!textlen)
378 {
379 *reinterpret_cast<FILETIME*>(dest) = pft;
380 return sizeof(FILETIME);
381 }
382 SYSTEMTIME dt;
384 len = _sntprintf(buf, COUNTOF(buf), _T("%d/%d/%d %02d:%02d:%02d.%02d"),
385 dt.wMonth, dt.wDay, dt.wYear,
386 dt.wHour, dt.wMinute, dt.wSecond, dt.wMilliseconds / 10);
387 if (textlen > len)
388 textlen = len;
389 memcpy(dest, buf, textlen * sizeof(tchar));
390 *(reinterpret_cast<LPTSTR>(dest) + textlen) = _T('\0');
391 return len;
392 };
393
394 switch (index) {
395 case FileHandle:
396 if (textlen)
397 return 0;
398 *reinterpret_cast<HFILE *>(dest) = FHdl;
399 return sizeof(FHdl);
400 default:
401 if (InfoPresent) {
402 switch(index) {
403 case StorageSize:
404 if (!textlen) {
405 *reinterpret_cast<unsigned long *>(dest) = FileLength;
406 return sizeof(FileLength);
407 }
408 else {
409 tchar buf[10];
410 int len = _stprintf(buf, _T("%ld"), FileLength);
411 if (textlen > len)
412 textlen = len;
413 memcpy(dest, buf, textlen*sizeof(tchar));
414 *(reinterpret_cast<LPTSTR>(dest) + textlen) = 0;
415 return len;
416 }
417 case CreateTime:
418 return formatFileTime(FileCreateTime, dest, textlen);
419 case ModifyTime:
420 return formatFileTime(FileUpdateTime, dest, textlen);
421 case AccessTime:
422 return formatFileTime(FileAccessTime, dest, textlen);
423 }
424 }
425 return TDocument::GetProperty(index, dest, textlen);
426 }
427}
428
429//
430/// Sets the property data, which must be in the native data type (either string or
431/// binary).
432//
433bool
434TFileDocument::SetProperty(int prop, const void * src)
435{
436 // File properties currently not settable
437 //
438 return TDocument::SetProperty(prop, src);
439}
440
441//
442/// Overrides TDocument::InStream and provides generic input for the particular
443/// storage medium. InStream returns a pointer to a TInStream. mode is a combination
444/// of the ios bits defined in iostream.h. strmId is not used for file documents.
445/// The view reads data from the document as a stream or through stream functions.
446//
448TFileDocument::InStream(int omode, LPCTSTR /*strmId*/)
449{
450 HFILE fhdl;
451 streampos seekpos;
452 if (omode == ofParent)
453 omode = GetOpenMode();
454 if (!(omode & ofRead))
455 return nullptr;
456 if ((fhdl = FHdl) == HFILE_ERROR) { // if file not open at document level
457 if ((fhdl=OpenThisFile (omode, GetDocPath(), &seekpos)) == HFILE_ERROR)
458 return nullptr;
459 }
460 else {
461#if 0 // suggested by Greg Chicares
462 omode = GetOpenMode() ? (GetOpenMode() & ~ofBinary) | (omode & ofBinary)
463 : omode;
464 omode |= PREV_OPEN;
465#else
466 ::_lclose(FHdl);
467 FHdl = HFILE_ERROR;
468 if ((fhdl=OpenThisFile (omode, GetDocPath(), &seekpos)) == HFILE_ERROR)
469 return nullptr;
470#endif
471 }
472 return new TFileInStream(*this, fhdl, omode, seekpos);
473}
474
475//
476/// Overrides TDocument::OutStream and provides generic input for the particular
477/// storage medium. OutStream returns a pointer to a TOutStream. mode is a
478/// combination of the ios bits defined in iostream.h. strmId is not used for file
479/// documents. Instead, the view reads data from the document through stream
480/// functions.
481//
483TFileDocument::OutStream(int omode, LPCTSTR /*strmId*/)
484{
485 HFILE fhdl;
486 streampos seekpos;
487 if (omode == ofParent)
488 omode = GetOpenMode();
489 if (!(omode & ofWrite))
490 return nullptr;
491 if ((fhdl = FHdl) == HFILE_ERROR) { // if file not open at document level
492 if ((fhdl=OpenThisFile (omode, GetDocPath(), &seekpos)) == HFILE_ERROR)
493 return nullptr;
494 }
495 else {
496#if 0 // suggested by Greg Chicares
497 omode = GetOpenMode() ? (GetOpenMode() & ~ofBinary) | (omode & ofBinary)
498 : omode;
499 omode |= PREV_OPEN;
500#else
501 ::_lclose(FHdl);
502 FHdl = HFILE_ERROR;
503 if ((fhdl=OpenThisFile (omode, GetDocPath(), &seekpos)) == HFILE_ERROR)
504 return nullptr;
505#endif
506 }
507 return new TFileOutStream(*this, fhdl, omode, seekpos);
508}
509
510//----------------------------------------------------------------------------
511
512//
513//
514//
515TFileInStream::~TFileInStream()
516{
517 (static_cast<TFileDocument&>(Doc)).CloseThisFile(buf.xfd, GetOpenMode());
518}
519
520//
521//
522//
523TFileOutStream::~TFileOutStream()
524{
525 if (buf.out_waiting())
526 buf.overflow(EOF);
527 (static_cast<TFileDocument&>(Doc)).CloseThisFile(buf.xfd, GetOpenMode());
528}
529
530//----------------------------------------------------------------------------
531// class TFileBuf
532//
533
534const int B_size = 516; // natural size for a file buffer, plus 4 for putback;
535
536//
537// Make a TFileBuf attached to an open fd
538//
539TFileBuf::TFileBuf(int fhdl, int omode, streampos seekpos)
540{
541 base_ = ebuf_ = nullptr;
542 xfd = fhdl; // assumed to be valid
543 mode = omode; // this may not represent the actual mode opened previously
544 last_seek = seekpos;
545 tchar* p = new tchar[B_size];
546 if (p) {
547 setb(p, p+B_size, 1); // ~streambuf() will delete buffer
548 setp(p+4, p+4);
549 setg(p, p+4, p+4);
550 }
551}
552
553//
554// Seek file to position.
555// We take a simple approach, and don't check for small position changes
556// within the current buffer.
557//
558TFileBuf::pos_type TFileBuf::seekoff(off_type off, ios_base::seekdir dir,
559 ios_base::openmode /*which*/)
560{
561 streamsize loff = static_cast<streamsize>(off);
562 if (out_waiting()) { // flush the output
563 if (sync() == eof())
564 return eof();
565 }
566 else if (dir == ios::cur) {
567 streamsize count = in_avail();
568 if (count != 0) {
569 loff -= count;
570
571 // if we're in text mode, need to allow for newlines
572 // in the buffer
573 if ((mode & ofBinary) == 0) {
574 tchar *tptr = gptr();
575 while (tptr != egptr())
576 if (*tptr++ == _T('\n'))
577 loff--;
578 }
579 }
580 }
581
582 if (!IsRepresentable<LONG>(loff)) // Need check, because _llseek takes LONG lOffset argument.
583 return streampos(eof());
584 LONG lOffset = static_cast<LONG>(loff);
585 int w = (dir==ios::beg) ? SEEK_SET : ((dir==ios::cur) ? SEEK_CUR:SEEK_END);
586 last_seek = ::_llseek(xfd, lOffset, w);
587
588 if (!unbuffered() && base()) { // set up get and put areas
589 size_t pb = (blen() > 8) ? 4 : 1; // putback area size
590 tchar *b = base();
591 setp(b + pb, b + pb);
592 setg(b, b + pb, b + pb);
593 }
594 return (last_seek == streampos(HFILE_ERROR)) ? streampos(eof()) : last_seek;
595}
596
597//
598//
599//
600int TFileBuf::sync()
601{
602 uint count = out_waiting();
603 if (count) {
605 tchar* curp;
606 tchar* srcp = pbase();
607 tchar* endp = srcp + count;
608
609 // Convert LF's to CR/LF if text mode
610 //
611 if ((mode & ofBinary) == 0) {
612 for (curp = srcp; curp < endp; curp++) {
613 if (*curp == _T('\n')){
614 *curp = _T('\r');
615 count = static_cast<int>(curp - srcp) + 1;
616 if (::_lwrite(xfd, _W2A(srcp), count) != count)
617 return eof();
618 *(srcp = curp) = _T('\n');
619 }
620 }
621 count = uint(curp - srcp); // write what remains in the buffer below
622 }
623 if (::_lwrite(xfd, _W2A(srcp), count) != count)
624 return eof();
625
626 // reset get and put areas
627 int pb = (blen() > 8) ? 4 : 1; // putback area size
628 tchar* b = base();
629 setp(b+pb, b+blen());
630 setg(b, b+pb, b+pb);
631 }
632 else if (in_avail()) {
633 last_seek = ::_llseek(xfd, long(-in_avail()), SEEK_CUR);
634 setg(eback(), gptr(), gptr());
635 setp(gptr(), gptr());
636 if (last_seek == streampos(HFILE_ERROR))
637 return eof();
638 }
639 return 0;
640}
641
642//
643//
644//
645TFileBuf::int_type
646TFileBuf::underflow()
647{
648 if ((mode & (ofRead | ofWrite)) == ofWrite)
649 return eof();
650
651 if (in_avail()) // no action needed
652 return static_cast<tchar>(*gptr());
653
654 int c = 0; // the return value
655 int count; // input character count
656
657 if (!unbuffered() && base()) { // this is buffered
658 if (sync() != 0)
659 return eof();
660
661 // find buffer data
662 int pb = (blen() > 8) ? 4 : 1; // putback area size
663 tchar* begp = base() + pb;
664
665 // read in a new buffer
666 count = ::_lread(xfd, begp, blen()-pb);
667 if (count == HFILE_ERROR)
668 return eof();
669
670 // remove CR's if text mode
671 if ((mode & ofBinary) == 0) {
672 tchar* endp = begp + count;
673 tchar* dstp = 0;
674 tchar* srcp = 0; // initialized only to prevent compiler warning
675 tchar* curp;
676
677 for (curp = begp; curp < endp; curp++) {
678 if (*curp == _T('\r')) {
679 if (dstp) {
680 memcpy(dstp, srcp, static_cast<int>(curp - srcp));
681 dstp += static_cast<int>(curp - srcp);
682 }
683 else
684 dstp = curp;
685 srcp = curp + 1;
686 }
687 }
688 if (dstp) {
689 endp = dstp + static_cast<int>(curp - srcp);
690 if (curp != srcp)
691 memcpy(dstp, srcp, static_cast<int>(curp - srcp));
692 }
693 count = static_cast<int>(endp - begp);
694 }
695 // set up get and put areas
696 setg(base(), begp, begp + count);
697 setp(begp, begp);
698
699 if (count)
700 c = static_cast<utchar>(*gptr());
701 }
702 else { // this is not buffered
703 for (;;) {
704 count = ::_lread(xfd, lahead, 1);
705 if (count == HFILE_ERROR) {
706 c = eof();
707 setg(nullptr, nullptr, nullptr);
708 }
709 else {
710 c = static_cast<utchar>(lahead[0]);
711 if ((mode & ofBinary) == 0 && c == _T('\r'))
712 continue;
713 setg(lahead, lahead, lahead+1);
714 }
715 break;
716 }
717 }
718 if (!count)
719 c = eof(); // end of file
720 return c;
721}
722
723//
724// Always flush
725//
726TFileBuf::int_type TFileBuf::overflow(int_type c)
727{
728 if ((mode & (ofRead | ofWrite)) == ofRead)
729 return eof();
730
731 if (unbuffered() || !base()) {
732 if (c != eof()) {
734 uint count;
735 tchar b[2];
736 if (c == _T('\n') && (mode & ofBinary) == 0) {
737 b[0] = _T('\r');
738 b[1] = static_cast<tchar>(c);
739 count = 2;
740 }
741 else {
742 b[0] = static_cast<tchar>(c);
743 count = 1;
744 }
745 if (::_lwrite(xfd, _W2A(b), count) != count)
746 return eof();
747 }
748 }
749 else { // now we know this is buffered and state is not bad
750
751 // resets get and put areas
752 if (sync() != 0)
753 return eof();
754
755 // reset get and put areas
756 int pb = (blen() > 8) ? 4 : 1; // putback area size
757 tchar *b = base();
758 setp(b+pb, b+blen());
759 setg(b, b+pb, b+pb);
760
761 if (c != eof()) {
762 sputc(static_cast<tchar>(c));
763 gbump(1); // pptr and gptr must be the same
764 }
765 }
766 return 1;
767}
768
769tstreambuf * TFileBuf::setbuf(char_type *s, streamsize n)
770{
771 delete[] base_;
772 base_ = s;
773 ebuf_ = s + n;
774 return this;
775}
776
777TFileBuf::pos_type TFileBuf::seekpos(pos_type sp,
778 ios_base::openmode which){
779 return seekoff(streamoff(sp), ios::beg, which);
780}
781
782//----------------------------------------------------------------------------
783// class TFileStreamBase
784//
785
786//
787//
788//
789TFileStreamBase::TFileStreamBase(int fhdl, int omode, streampos seekpos)
790:
791 buf(fhdl, omode, seekpos)
792{
793 tios::init(&buf);
794}
795
796
798
799#if OWL_PERSISTENT_STREAMS
800
801//
802//
803//
804void*
805TFileDocument::Streamer::Read(ipstream& is, uint32 /*version*/) const
806{
807 TFileDocument* o = GetObject();
808 o->FHdl = HFILE_ERROR; // initialize to closed file
809 o->InfoPresent = false;
811 return o;
812}
813
814//
815//
816//
817void
818TFileDocument::Streamer::Write(opstream& os) const
819{
820 // assumed that document is committed at this point
821 WriteBaseObject((TDocument*)GetObject(), os);
822}
823
824#endif
825
826} // OWL namespace
827//=========================================================================================
An abstract base class, TDocument is the base class for all document objects and serves as an interfa...
Definition docview.h:187
Derived from TDocument, TFileDocument opens and closes views and provides stream support for views.
Definition filedoc.h:34
Derived from TStream and istream, TInStream is a base class used to define input streams for document...
Definition docview.h:594
Derived from TStream and ostream, TOutStream is a base class used to create output storage streams fo...
Definition docview.h:605
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _tcscmp
Definition cygwin.h:75
#define _stprintf
Definition cygwin.h:88
#define _T(x)
Definition cygwin.h:51
Definition of class TFileDocument.
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define IMPLEMENT_STREAMABLE1(cls, base1)
Definition objstrm.h:1725
const uint vnDocClosed
document has just been closed
Definition docview.h:108
const uint vnDocOpened
document has just been opened
Definition docview.h:107
#define IS_PREV_OPEN(omode)
Definition docview.h:98
#define PREV_OPEN
Definition docview.h:97
@ ofRead
ios::in, open for reading
Definition docview.h:63
@ ofTruncate
ios::trunc, truncate file if already exists
Definition docview.h:68
@ shMask
Definition docview.h:95
@ ofReadWrite
Definition docview.h:65
@ shRead
DENY_WRITE functionality.
Definition docview.h:91
@ shDefault
use stream implementation default value
Definition docview.h:94
@ ofParent
use open mode of parent storage
Definition docview.h:62
@ ofNoReplace
ios::noreplace, open fails if file already exists
Definition docview.h:79
@ ofAppend
ios::app, append mode: all additions at eof
Definition docview.h:67
@ ofWrite
ios::out, open for writing
Definition docview.h:64
@ ofAtEnd
ios::ate, seek to eof upon original open
Definition docview.h:66
@ ofBinary
Definition docview.h:81
@ shReadWrite
DENY_NONE functionality.
Definition docview.h:93
@ ofNoCreate
ios::nocreate, open fails if file doesn't exist
Definition docview.h:74
@ shCompat
for non-compliant applications, avoid if possible
Definition docview.h:89
#define _W2A(lpw)
Definition memory.h:219
#define _USES_CONVERSION
Definition memory.h:217
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
const int B_size
Definition filedoc.cpp:534
char tchar
Definition defs.h:77
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
std::ios tios
Definition strmdefs.h:42
unsigned char utchar
Definition defs.h:78
#define _OWLCLASS
Definition defs.h:338
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
Definition defs.h:376