OpenCores
URL https://opencores.org/ocsvn/ht_tunnel/ht_tunnel/trunk

Subversion Repositories ht_tunnel

[/] [ht_tunnel/] [tags/] [START/] [bench/] [core/] [require.h] - Blame information for rev 21

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acastong
//: :require.h
2
// Test for error conditions in programs
3
// Local "using namespace std" for old compilers
4
#ifndef REQUIRE_H
5
#define REQUIRE_H
6
#include <cstdio>
7
#include <cstdlib>
8
#include <fstream>
9
#include <string>
10
 
11
inline void require(bool requirement,
12
  const std::string& msg = "Requirement failed"){
13
  using namespace std;
14
  if (!requirement) {
15
    fputs(msg.c_str(), stderr);
16
    fputs("\n", stderr);
17
    exit(1);
18
  }
19
}
20
 
21
inline void verify(bool requirement,
22
  const std::string& msg = "Requirement failed"){
23
  using namespace std;
24
  if (!requirement) {
25
    fputs(msg.c_str(), stdout);
26
    fputs("\n", stdout);
27
  }
28
}
29
 
30
 
31
inline void requireArgs(int argc, int args,
32
  const std::string& msg =
33
    "Must use %d arguments") {
34
  using namespace std;
35
   if (argc != args + 1) {
36
     fprintf(stderr, msg.c_str(), args);
37
     fputs("\n", stderr);
38
     exit(1);
39
   }
40
}
41
 
42
inline void requireMinArgs(int argc, int minArgs,
43
  const std::string& msg =
44
    "Must use at least %d arguments") {
45
  using namespace std;
46
  if(argc < minArgs + 1) {
47
    fprintf(stderr, msg.c_str(), minArgs);
48
    fputs("\n", stderr);
49
    exit(1);
50
  }
51
}
52
 
53
inline void assure(std::ifstream& in,
54
  const std::string& filename = "") {
55
  using namespace std;
56
  if(!in) {
57
    fprintf(stderr, "Could not open file %s\n",
58
      filename.c_str());
59
    exit(1);
60
  }
61
}
62
 
63
inline void assure(std::ofstream& out,
64
  const std::string& filename = "") {
65
  using namespace std;
66
  if(!out) {
67
    fprintf(stderr, "Could not open file %s\n",
68
      filename.c_str());
69
    exit(1);
70
  }
71
}
72
#endif // REQUIRE_H ///:~
73
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.