Reference documentation for deal.II version 9.0.0
job_identifier.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/job_identifier.h>
17 #include <ctime>
18 
19 #ifdef DEAL_II_HAVE_UNISTD_H
20 # include <unistd.h>
21 #endif
22 
23 DEAL_II_NAMESPACE_OPEN
24 
25 
26 JobIdentifier dealjobid;
27 
28 
30 {
31  time_t t = std::time(nullptr);
32  id = std::string("JobId ");
33 
34 #if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
35  char name[100];
36  gethostname(name,99);
37  id += std::string(name) + std::string(" ");
38 #else
39  id += std::string("unknown ");
40 #endif
41 
42  id += std::string(std::ctime(&t));
43 }
44 
45 
46 const std::string
48 {
49  return id;
50 }
51 
52 
53 std::string
54 JobIdentifier::base_name(const char *filename)
55 {
56  std::string name(filename);
57  std::string::size_type pos;
58  pos = name.rfind('/');
59  if (pos != std::string::npos)
60  name.erase(0, pos + 1);
61  pos = name.rfind('.');
62  if (pos != std::string::npos)
63  name.erase(pos, name.size());
64  return name;
65 }
66 
67 
68 
69 DEAL_II_NAMESPACE_CLOSE
const std::string operator()() const
static std::string base_name(const char *filename)
std::string id