SheafSystem  0.0.0.0
sheaf.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Definitions for class sheaf_constants
19 
20 #include "SheafSystem/sheaf.h"
21 
22 #include "SheafSystem/error_message.h"
23 #include "SheafSystem/std_cstdlib.h"
24 #include "SheafSystem/std_cmath.h"
25 #include "SheafSystem/std_iostream.h"
26 
27 using namespace std;
28 
29 // =============================================================================
30 // MISC FACET
31 // =============================================================================
32 
34 void
35 sheaf::
37 {
38  // Check to see if the environment variable LPS_SCRIPT_HAS_RUN
39  // has been set. If not, exit with a fatal error message;
40  // otherwise do nothing.
41 
42  if(getenv("LPS_SCRIPT_HAS_RUN") == 0)
43  {
44  post_fatal_error_message("LPS script has not been executed.");
45  }
46 }
47 
49 std::string
50 sheaf::
51 filename_from_cmdline(std::string xargv)
52 {
53  string result;
54  // Look for backslashes no matter the OS
55  string key = "\\";
56 
57  // Find any backslashes in the filename and convert them to slashes
58  string::size_type bslash = xargv.rfind(key);
59  if (bslash!=string::npos)
60  xargv.replace (bslash,key.length(),"/");
61 
62  // find the rightmost slash in the filename
63  string::size_type slash = xargv.rfind('/');
64 
65  // There weren't any path delimiters; return argv.
66  if (slash == string::npos)
67  {
68  result = xargv;
69  }
70  else // Return the undelimited string value of argv.
71  {
72  result = xargv.substr(slash+1);
73  }
74 
75  return result;
76 }
77 
79 std::string
80 sheaf::
82 {
83  // Expansion of the CVS keyword "<dollars>Name<dollars>" looks like this:
84  // <dollars><'Name'><colon><space><tag name><space><dollars>
85  // Start reading at position 7, and read all but the last two positions.
86 
87  string result = RELEASE_TAG.substr(7,RELEASE_TAG.length()-9);
88 
89  if (result.empty())
90  {
91  // If there are no characters in the result, then we are dealing with the head.
92  return "HEAD";
93  }
94  else
95  {
96  return result;
97  }
98 }
99 
100 bool
101 sheaf::
102 isunordered_or_equals(float x1, float x2)
103 {
104  // Preconditions:
105 
106  // Body:
107 
108  // isunordered not available in Visual C++ 2008
109  // != condition instead.
110  // bool result = std::isunordered(x1, x2) || (x1 == x2);
111 
112  bool result = (x1 != x1) || (x2 != x2) || (x1 == x2);
113 
114  // Postconditions:
115 
116  // Exit:
117 
118  return result;
119 }
120 
121 bool
122 sheaf::
123 isunordered_or_equals(double x1, double x2)
124 {
125  // Preconditions:
126 
127  // Body:
128 
129  // isunordered not available in Visual C++ 2008
130  // != condition instead.
131  // bool result = std::isunordered(x1, x2) || (x1 == x2);
132 
133  bool result = (x1 != x1) || (x2 != x2) || (x1 == x2);
134 
135  // Postconditions:
136 
137  // Exit:
138 
139  return result;
140 }
141 
142 bool
143 sheaf::
144 isunordered_or_equals(long double x1, long double x2)
145 {
146  // Preconditions:
147 
148  // Body:
149 
150  // isunordered not available in Visual C++ 2008
151  // != condition instead.
152  // bool result = std::isunordered(x1, x2) || (x1 == x2);
153 
154  bool result = (x1 != x1) || (x2 != x2) || (x1 == x2);
155 
156  // Postconditions:
157 
158  // Exit:
159 
160  return result;
161 }
SHEAF_DLL_SPEC void check_lps_script_has_run()
Function to test for whether the LPS script has been executed.
Definition: sheaf.cc:36
const std::string RELEASE_TAG
The CVS branch tag this file is part of.
Definition: sheaf.h:136
STL namespace.
SHEAF_DLL_SPEC std::string get_release_tag()
Returns the CVS branch tag for this codebase. .
Definition: sheaf.cc:81
SHEAF_DLL_SPEC std::string filename_from_cmdline(std::string xargv)
Method to strip any command line down to it&#39;s rightmost delimited element . Used in unit test routine...
Definition: sheaf.cc:51
SHEAF_DLL_SPEC bool isunordered_or_equals(float x1, float x2)
True if isunordered(x1, x2) or x1 == x2.
Definition: sheaf.cc:102