469,908 Members | 2,212 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,908 developers. It's quick & easy.

who do know std::ctime() how implement? Help me?

I write my own class Cfile, I want to know what about implement ctime().Who
help me?
My use function ctime, I sign it with $$$.
my class Cfile:
#------------------------
file.h
#---------------------------
#include <io.h>
#include <ctime>
#include <string>

#ifndef fileH
#define fileH
using namespace std;
bool is_path(const char* name);
//
class Cfile{
public:
bool is_path();
long size();
std::string name();
std::string attrib();
std::string create_time();
std::string access_time();
std::string write_time();
std::string date();
void display();
void print();
Cfile(const std::string& name);
Cfile(const char* name);
~Cfile();
protected:
bool initialize(const char* name);
bool clean();
char m_full_fname[260];
long m_hFile;
struct _finddata_t m_fileinfo; //file_information
};
#endif //fileH
#-------------------------
file.cpp
#---------------------------

#include <string>
#include <cstring>
#include <ctime>
///////////////
#include "dir.h"
//////////////////////////
#include "e:\program\wukexin\file\file.h"
#include "e:\program\wukexin\timer\timer.h"
#include "e:\program\wukexin\tracer\tracer.h"
#include "e:\program\wukexin\help\help.h"
//
Cfile::Cfile(const std::string& name){
#ifdef DEBUG
#endif //
initialize( name.c_str() );
};
//
Cfile::Cfile(const char* name){
#ifdef DEBUG
Ctracer tracer( string("Cfile"),string(name) );
Ctimer timer( string("Cfile"), string(name));
#endif //debug
initialize(name);
};
//
Cfile::~Cfile(){
#ifdef DEBUG
Ctracer tracer("Cfile::~Cfile()");
Ctimer timer("Cfile::~Cfile()");
#endif //
clean();
};
//
bool Cfile::initialize(const char* name){
#ifdef DEBUG
//string message("initialize"),arg(name);
Ctracer tracer( string("initialize"), string(name) );
Ctimer timer( string("initialize"), string(name) );
#endif //
bool result(false);
#ifdef __BORLAND__
const int PATHMAX=260;
char temp[PATHMAX];
strcpy(temp,name);
m_hFile=_findfirst( temp, &m_fileinfo);
#else
m_hFile=_findfirst( name, &m_fileinfo);
#endif //borland
if( -1 != m_hFile ){
result=true;
}
#ifdef DEBUG
tracer.append( to_string(m_hFile) );
#endif //debug
return result;
};
bool Cfile::clean(){
#ifdef DEBUG
Ctracer tracer("Cfile::clean()");
Ctimer timer("Cfile::clean()");
#endif //debug

#ifdef __BORLAND__
cout<<"m_hFile="<<m_hFile<<endl;
#else
#endif //borland
bool result(false);
if( 0 == _findclose(m_hFile) ){
result=true;
}
#ifdef DEBUG
tracer.append( to_string(result) );
#endif //debug
return result;
};
//
bool Cfile::is_path(){
#ifdef DEBUG
Ctracer tracer( "Cfile::is_path()" );
Ctimer timer( "Cfile::is_path()" );
#endif //
bool result(false);
if( m_fileinfo.attrib & _A_SUBDIR ){
result=true;
}
return result;
};
//
long Cfile::size(){
#ifdef DEBUG
Ctracer tracer("Cfile::size()");
Ctimer timer("Cfile::size()");
#endif //
long result(m_fileinfo.size);
return result;
};
//
string Cfile::name(){
#ifdef DEBUG
Ctracer tracer("Cfile::name()");
Ctimer timer("Cfile::name()");
#endif //
string result(m_fileinfo.name);
return result;
};
//
string Cfile::attrib(){
#ifdef DEBUG
Ctracer tracer("Cfile::attrib()");
Ctimer timer("Cfile::attrib()");
#endif //
string result;
if( m_fileinfo.attrib & _A_SUBDIR ){
result.append("d");
}
if( m_fileinfo.attrib & _A_HIDDEN ){
result.append("h");
}
if( m_fileinfo.attrib & _A_ARCH ){
result.append("a");
}
if( m_fileinfo.attrib & _A_RDONLY ){
result.append("r");
}
if( m_fileinfo.attrib & _A_SYSTEM ){
result.append("s");
}
if( m_fileinfo.attrib & _A_VOLID ){
result.append("l");
}
if( !result.empty() ){
result.insert(result.begin(),1,'-');
}
#ifdef DEBUG
tracer.append(result);
#endif //debug
return result;
};
//
string Cfile::create_time(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
return result;
};
//
string Cfile::access_time(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
return result;
};
//
string Cfile::write_time(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
time_t *ptr=&m_fileinfo.time_write;
result=ctime(ptr);//$$$
#ifdef DEBUG
tracer.append(result);
#endif //DEBUG
return result;
};
//
string Cfile::date(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
return result;
};
//
void Cfile::display(){
#ifdef DEBUG
Ctracer tracer("Cfile::display()");
Ctimer timer("Cfile::display()");
#endif //
};
//
void Cfile::print(){
#ifdef DEBUG
Ctracer tracer("Cfile::print()");
Ctimer timer("Cfile::print()");
#endif //
};


Jul 23 '05 #1
0 2045

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by GGG | last post: by
1 post views Thread by wukexin | last post: by
5 posts views Thread by berkay | last post: by
6 posts views Thread by ma740988 | last post: by
8 posts views Thread by B Williams | last post: by
4 posts views Thread by Gary Wessle | last post: by
11 posts views Thread by aisling.cronin | last post: by
4 posts views Thread by Pietro Cerutti | last post: by
9 posts views Thread by Lars Uffmann | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.