source: trunk/IPs/systemC/processor/Morpheo/Common/include/Filename.h @ 100

Last change on this file since 100 was 100, checked in by rosiere, 15 years ago

1) Bug fix (Operation, Instruction)
2) Modif Return Address Stack
3) Add Soft Test
4) Add Soc Test

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#ifndef Morpheo_Filename_h
2#define Morpheo_Filename_h
3
4/*
5 * $Id: Filename.h 100 2009-01-08 13:06:27Z rosiere $
6 *
7 * [ Description ]
8 *
9 */
10
11#include "Common/include/ToString.h"
12#include <fstream>
13#include <sstream>
14#include <sys/time.h>
15#include <unistd.h>
16
17namespace morpheo {
18
19  std::string filename (std::string directory,
20                        std::string filename_prefix,
21                        std::string filename_suffix,
22                        std::string extension,
23                        bool        with_date,
24                        bool        with_pid,
25                        bool        overwrite
26                        )
27  {
28    std::string str = directory+"/"+filename_prefix;
29
30    if (with_date)
31      {
32        time_t current_time;
33        time (&current_time);
34       
35        struct tm * _localtime = localtime (&current_time);
36       
37        int year = 1900+_localtime->tm_year;
38        int mon  =    1+_localtime->tm_mon ;
39        int mday =      _localtime->tm_mday;
40        int hour =      _localtime->tm_hour;
41        int min  =      _localtime->tm_min ;
42        int sec  =      _localtime->tm_sec ;
43       
44        str+= "_"+                     toString<int>(year) 
45                 +((mon <10)?"0":"") + toString<int>(mon ) 
46                 +((mday<10)?"0":"") + toString<int>(mday) 
47             +"_"+((hour<10)?"0":"") + toString<int>(hour) 
48                 +((min <10)?"0":"") + toString<int>(min ) 
49                 +((sec <10)?"0":"") + toString<int>(sec ); 
50      }
51
52    if (with_pid)
53      {
54        str+="_"+toString<pid_t>(getpid());
55      }
56   
57    str+=filename_suffix;
58
59    if (not overwrite)
60      {
61        int  it = 0;
62        bool find;
63        do
64          {
65            find = false;
66           
67            std::ifstream inputStream;
68            std::string name = str+((it!=0)?("_"+toString<int>(it)):"");
69
70            inputStream.open(name.c_str(),std::ios_base::in);
71           
72            if (inputStream)
73              {
74                find = true;
75                it ++;
76              }           
77            inputStream.close();
78          }
79        while (find);
80
81        str+= str+((it!=0)?("_"+toString<int>(it)):"");
82      }
83
84    str+="."+extension;
85
86    return str;
87  }
88 
89}; // end namespace morpheo             
90
91#endif
Note: See TracBrowser for help on using the repository browser.