Reference documentation for deal.II version 9.1.0-pre
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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/job_identifier.h>
17 
18 #include <ctime>
19 
20 #ifdef DEAL_II_HAVE_UNISTD_H
21 # include <unistd.h>
22 #endif
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 
27 JobIdentifier dealjobid;
28 
29 
31 {
32  time_t t = std::time(nullptr);
33  id = std::string("JobId ");
34 
35 #if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
36  char name[100];
37  gethostname(name, 99);
38  id += std::string(name) + std::string(" ");
39 #else
40  id += std::string("unknown ");
41 #endif
42 
43  id += std::string(std::ctime(&t));
44 }
45 
46 
47 const std::string
49 {
50  return id;
51 }
52 
53 
54 std::string
55 JobIdentifier::base_name(const char *filename)
56 {
57  std::string name(filename);
58  std::string::size_type pos;
59  pos = name.rfind('/');
60  if (pos != std::string::npos)
61  name.erase(0, pos + 1);
62  pos = name.rfind('.');
63  if (pos != std::string::npos)
64  name.erase(pos, name.size());
65  return name;
66 }
67 
68 
69 
70 DEAL_II_NAMESPACE_CLOSE
static std::string base_name(const char *filename)
std::string id
const std::string operator()() const