Commits

Chris Park  committed 0fc635c

merge support of 'bin' binary PCL files

  • Participants
  • Parent commits 0cb5f19

Comments (0)

Files changed (3)

 const char	CPCLImpl::c_szNAME[]		= "NAME";
 const char	CPCLImpl::c_szOne[]			= "1";
 const char	CPCLImpl::c_szExtension[]	= ".pcl";
+const char	CPCLImpl::c_szBinExtension[]	= ".bin";
 
 struct SNeighbors {
 	CFullMatrix<pair<size_t, float> >	m_MatNeighbors;
 
 /*!
  * \brief
+ * Create a new PCL by reading from text or binary
+ * 
+ * \param szFile
+ * File from which PCL file is loaded.
+ * 
+ * \returns
+ * True if the PCL was opened successfully.
+ * 
+ */
+bool CPCL::Open( const char* szFile, size_t iSkip ) {
+  std::ifstream	ifsm;
+  if( szFile )
+    ifsm.open( szFile );
+  
+    // is this a binary binary file?
+  if( !strcmp( szFile + strlen( szFile ) - strlen(c_szBinExtension ), c_szBinExtension ) )
+    return OpenBinary(szFile ? ifsm : cin);  
+  else
+  // is this a text based PCL file?
+    return Open( szFile ? ifsm : cin, iSkip );
+}
+
+/*!
+ * \brief
+ * Save a PCL to the given text file.
+ * 
+ * \param szFile
+ * File into which PCL file is saved.
+ * 
+ * \remarks
+ * If null, output defaults to stdout.
+ * 
+ * \see
+ * Save
+ */
+void CPCL::Save( const char* szFile ) {
+  std::ofstream	ofsm;
+  
+  if( szFile )
+    ofsm.open( szFile );
+  
+  // Save as text based PCL file?
+  if( !strcmp( szFile + strlen( szFile ) - strlen(c_szExtension ), c_szExtension ) )
+    Save( szFile ? ofsm : cout );
+  else
+    // Save as binary binary file?
+    SaveBinary(szFile ? ofsm : cout);  
+}
+
+/*!
+ * \brief
  * Create a new PCL by copying the given one.
  * 
  * \param PCL
  * CFullMatrix::SaveBinary method.
  * 
  * \see
- * OpenBinary
+ * SaveBinary
  */
 void CPCL::SaveBinary( std::ostream& ostm ) const {
 	uint32_t	iTmp;
  * Stream from which PCL file is loaded.
  * 
  * \see
- * SaveBinary
+ * OpenBinary
  */
-void CPCL::OpenBinary( std::istream& istm ) {
+bool CPCL::OpenBinary( std::istream& istm ) {
 	uint32_t	iTmp;
 	size_t		i;
 
 
 	m_Data.Initialize( GetGenes( ), GetExperiments( ) );
 	for( i = 0; i < m_Data.GetRows( ); ++i )
-		istm.read( (char*)m_Data.Get( i ), GetExperiments( ) * sizeof(*m_Data.Get( i )) ); }
+		istm.read( (char*)m_Data.Get( i ), GetExperiments( ) * sizeof(*m_Data.Get( i )) ); 
+	
+	return true;
+}
 
 /*!
  * \brief
 		const std::vector<std::string>& vecstrExperiments );
 	void Open( const std::vector<std::string>& vecstrGenes, const std::vector<std::string>& vecstrExperiments,
 		const std::vector<std::string>& vecstrFeatures );
-	void OpenBinary( std::istream& istm );
+	bool OpenBinary( std::istream& istm );
 	void Save( std::ostream& ostm, const std::vector<size_t>* pveciGenes = NULL ) const;
 	void SaveBinary( std::ostream& ostm ) const;
 	void SaveGene( std::ostream& ostm, size_t iGene, size_t iOriginal = -1 ) const;
 	 * \see
 	 * Save
 	 */
-	void Save( const char* szFile = NULL ) const {
-		std::ofstream	ofsm;
-
-		if( szFile )
-			ofsm.open( szFile );
-		Save( szFile ? ofsm : std::cout ); }
-
+	void Save( const char* szFile = NULL );
+	
 	/*!
 	 * \brief
 	 * Load a PCL from the given text file.
 	 * \see
 	 * Save
 	 */
-	bool Open( const char* szFile, size_t iSkip ) {
-		std::ifstream	ifsm;
-
-		if( szFile )
-			ifsm.open( szFile );
-		return Open( szFile ? ifsm : cin, iSkip ); }
-
+	bool Open( const char* szFile, size_t iSkip );
+	
 	/*!
 	 * \brief
 	 * Load a PCL from the given text stream using the default number of skip columns.
 	static const char	c_szNAME[];
 	static const char	c_szOne[];
 	static const char	c_szExtension[];
-
+	static const char	c_szBinExtension[];
+	
 	typedef std::vector<std::string>		TVecStr;
 	typedef std::set<size_t>				TSetI;
 	typedef std::map<std::string, size_t>	TMapStrI;