SST  12.0.0
StructuralSimulationToolkit
namecheck.h
1 // Copyright 2009-2022 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2022, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_SST_NAMECHECK_H
13 #define SST_CORE_SST_NAMECHECK_H
14 
15 #include <string>
16 
17 namespace SST {
18 
19 class NameCheck
20 {
21 
22  /**
23  Checks to see if a name is valid according to the SST naming
24  convention.
25 
26  Names can start with a letter or an underscore, but not a
27  double underscore. Names also cannot consist of only an
28  underscore. There can also be a dot ('.') in the name, but
29  each segment on either side of the dot must be a valid name in
30  and of itself. Name cannot end with a dot. Anywhere a number
31  can go, you can also have a number wildcard with one of the
32  following formats: %d, %(some documentation)d. The use of dots
33  and wildcards can be turned on and off with the proper flags.
34 
35  @param name Name to check for validity
36 
37  @param allow_wildcard If true, the %d format is considered
38  valid, if false, using %d will result in a failed check
39 
40  @param allow_dot If true, a dot ('.') can be used in the name,
41  if false, using a dot will result in a failed check
42 
43  @return true if name is valid, false otherwise
44  */
45  static bool isNameValid(const std::string& name, bool allow_wildcard, bool allow_dot);
46 
47 public:
48  static inline bool isComponentNameValid(const std::string& name) { return isNameValid(name, false, true); }
49 
50  static inline bool isLinkNameValid(const std::string& name) { return isNameValid(name, false, true); }
51 
52  static inline bool isParamNameValid(const std::string& name) { return isNameValid(name, true, true); }
53 
54  static inline bool isPortNameValid(const std::string& name) { return isNameValid(name, true, true); }
55 
56  static inline bool isSlotNameValid(const std::string& name) { return isNameValid(name, false, false); }
57 };
58 
59 } // namespace SST
60 
61 #endif // SST_CORE_SST_NAMECHECK_H
Definition: namecheck.h:19