Panda3D
pathStore.cxx
1 // Filename: pathStore.cxx
2 // Created by: drose (10Feb03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pathStore.h"
16 
17 #include "string_utils.h"
18 #include "pnotify.h"
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: format_path_store
22 // Description: Returns the string corresponding to this method.
23 ////////////////////////////////////////////////////////////////////
24 string
25 format_path_store(PathStore store) {
26  switch (store) {
27  case PS_invalid:
28  return "invalid";
29 
30  case PS_relative:
31  return "relative";
32 
33  case PS_absolute:
34  return "absolute";
35 
36  case PS_rel_abs:
37  return "rel_abs";
38 
39  case PS_strip:
40  return "strip";
41 
42  case PS_keep:
43  return "keep";
44  }
45  nout << "**unexpected PathStore value: (" << (int)store << ")**";
46  return "**";
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: PathStore output operator
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 ostream &
54 operator << (ostream &out, PathStore store) {
55  return out << format_path_store(store);
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: string_path_store
60 // Description: Stores from a string, as might be input by the
61 // user, to one of the known PathStore types.
62 // Returns PS_invalid if the string is unknown.
63 ////////////////////////////////////////////////////////////////////
64 PathStore
65 string_path_store(const string &str) {
66  if (cmp_nocase(str, "relative") == 0 ||
67  cmp_nocase(str, "rel") == 0) {
68  return PS_relative;
69 
70  } else if (cmp_nocase(str, "absolute") == 0 ||
71  cmp_nocase(str, "abs") == 0) {
72  return PS_absolute;
73 
74  } else if (cmp_nocase_uh(str, "rel_abs") == 0) {
75  return PS_rel_abs;
76 
77  } else if (cmp_nocase(str, "strip") == 0) {
78  return PS_strip;
79 
80  } else if (cmp_nocase(str, "keep") == 0) {
81  return PS_keep;
82 
83  } else {
84  return PS_invalid;
85  }
86 }