xref: /trafficserver/include/tscore/I_Layout.h (revision 774f55f1)
1 /** @file
2 
3   Layout
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22 
23   @section details Details
24 
25   Part of the utils library which contains classes that use multiple
26   components of the IO-Core to implement some useful functionality. The
27   classes also serve as good examples of how to use the IO-Core.
28 
29  */
30 
31 #pragma once
32 
33 // use std string and string view for layout
34 #include <string>
35 
36 /**
37   The Layout is a simple place holder for the distribution layout.
38 
39  */
40 struct Layout {
41   Layout(std::string_view const _prefix = {});
42   ~Layout();
43 
44   /**
45    Setup the runroot for layout class
46    Return true if runroot is setup succesfully and false if runroot is not used
47    */
48   bool runroot_setup();
49 
50   /**
51    Return file path relative to Layout->prefix
52   */
53   std::string relative(std::string_view file);
54 
55   /**
56    update the sysconfdir to a test conf dir
57    */
58   void update_sysconfdir(std::string_view dir);
59 
60   /**
61    Return file path relative to dir
62    Example usage: Layout::relative_to(default_layout()->sysconfdir, "foo.bar");
63   */
64   static std::string relative_to(std::string_view dir, std::string_view file);
65 
66   /**
67    Return file path relative to dir
68    Store the path to buf. The buf should be large enough to store
69    Example usage: Layout::relative_to(default_layout()->sysconfdir, "foo.bar");
70   */
71   static void relative_to(char *buf, size_t bufsz, std::string_view dir, std::string_view file);
72 
73   /**
74    Creates a Layout Object with the given prefix.  If no
75    prefix is given, the prefix defaults to the one specified
76    at the compile time.
77   */
78   static void create(std::string_view const prefix = {});
79 
80   /**
81    Returns the Layout object created by create_default_layout().
82   */
83   static Layout *get();
84 
85   std::string prefix;
86   std::string exec_prefix;
87   std::string bindir;
88   std::string sbindir;
89   std::string sysconfdir;
90   std::string datadir;
91   std::string includedir;
92   std::string libdir;
93   std::string libexecdir;
94   std::string localstatedir;
95   std::string runtimedir;
96   std::string logdir;
97   std::string mandir;
98   std::string infodir;
99   std::string cachedir;
100 };
101