Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
d32333a0
Commit
d32333a0
authored
Oct 25, 2012
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
streamline the FILE_OUTPUTFORMATTER API for ease of use
parent
9cd011ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
35 deletions
+51
-35
richio.cpp
common/richio.cpp
+36
-0
richio.h
include/richio.h
+13
-14
kicad_plugin.cpp
pcbnew/kicad_plugin.cpp
+2
-21
No files found.
common/richio.cpp
View file @
d32333a0
...
...
@@ -453,6 +453,42 @@ void STRING_FORMATTER::StripUseless()
}
}
//-----<FILE_OUTPUTFORMATTER>----------------------------------------
FILE_OUTPUTFORMATTER
::
FILE_OUTPUTFORMATTER
(
const
wxString
&
aFileName
,
const
wxChar
*
aMode
)
throw
(
IO_ERROR
)
:
m_filename
(
aFileName
)
{
m_fp
=
wxFopen
(
aFileName
,
aMode
);
if
(
!
m_fp
)
{
wxString
msg
=
wxString
::
Format
(
_
(
"cannot open or save file '%s'"
),
m_filename
.
GetData
()
);
THROW_IO_ERROR
(
msg
);
}
}
FILE_OUTPUTFORMATTER
::~
FILE_OUTPUTFORMATTER
()
{
if
(
m_fp
)
fclose
(
m_fp
);
}
void
FILE_OUTPUTFORMATTER
::
write
(
const
char
*
aOutBuf
,
int
aCount
)
throw
(
IO_ERROR
)
{
if
(
1
!=
fwrite
(
aOutBuf
,
aCount
,
1
,
m_fp
)
)
{
wxString
msg
=
wxString
::
Format
(
_
(
"error writing to file '%s'"
),
m_filename
.
GetData
()
);
THROW_IO_ERROR
(
msg
);
}
}
//-----<STREAM_OUTPUTFORMATTER>--------------------------------------
...
...
include/richio.h
View file @
d32333a0
...
...
@@ -589,26 +589,25 @@ protected:
*/
class
FILE_OUTPUTFORMATTER
:
public
OUTPUTFORMATTER
{
FILE
*
m_fp
;
///< takes ownership
FILE
*
m_fp
;
///< takes ownership
wxString
m_filename
;
public
:
FILE_OUTPUTFORMATTER
(
FILE
*
fp
)
:
m_fp
(
fp
)
{
}
~
FILE_OUTPUTFORMATTER
()
{
if
(
m_fp
)
fclose
(
m_fp
);
}
/**
* Constructor
* @param aFileName is the full filename to open and save to as a text file.
* @param aMode is what you would pass to wxFopen()'s mode, defaults to wxT( "wt" )
* for text files that are to be created here and now.
* @throw IO_ERROR if the file cannot be opened.
*/
FILE_OUTPUTFORMATTER
(
const
wxString
&
aFileName
,
const
wxChar
*
aMode
=
wxT
(
"wt"
)
)
throw
(
IO_ERROR
);
~
FILE_OUTPUTFORMATTER
();
protected
:
//-----<OUTPUTFORMATTER>------------------------------------------------
void
write
(
const
char
*
aOutBuf
,
int
aCount
)
throw
(
IO_ERROR
)
{
fwrite
(
aOutBuf
,
aCount
,
1
,
m_fp
);
}
void
write
(
const
char
*
aOutBuf
,
int
aCount
)
throw
(
IO_ERROR
);
//-----</OUTPUTFORMATTER>-----------------------------------------------
};
...
...
pcbnew/kicad_plugin.cpp
View file @
d32333a0
...
...
@@ -184,18 +184,7 @@ void FP_CACHE::Save()
wxLogTrace
(
traceFootprintLibrary
,
wxT
(
"Creating temporary library file %s"
),
GetChars
(
tempFileName
)
);
FILE
*
fp
=
wxFopen
(
tempFileName
,
wxT
(
"wt"
)
);
if
(
!
fp
)
{
wxString
msg
=
wxString
::
Format
(
_
(
"cannot save footprint library file '%s'"
),
tempFileName
.
GetData
()
);
THROW_IO_ERROR
(
msg
);
}
FILE_OUTPUTFORMATTER
formatter
(
fp
);
// gets fp ownership
FILE_OUTPUTFORMATTER
formatter
(
tempFileName
);
m_owner
->
SetOutputFormatter
(
&
formatter
);
m_owner
->
Format
(
(
BOARD_ITEM
*
)
it
->
second
->
GetModule
()
);
...
...
@@ -316,15 +305,7 @@ void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProper
m_board
=
aBoard
;
FILE
*
fp
=
wxFopen
(
aFileName
,
wxT
(
"wt"
)
);
if
(
!
fp
)
{
m_error
.
Printf
(
_
(
"cannot open file '%s'"
),
aFileName
.
GetData
()
);
THROW_IO_ERROR
(
m_error
);
}
FILE_OUTPUTFORMATTER
formatter
(
fp
);
// gets ownership of fp
FILE_OUTPUTFORMATTER
formatter
(
aFileName
);
m_out
=
&
formatter
;
// no ownership
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment