Updated formatting of documentation plus a little reorganization.
[cmake.git] / Source / cmInstallCommandArguments.cxx
blobb529ccf929af91efa39b6b000311acc8fbca2a9e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallCommandArguments.cxx,v $
5 Language: C++
6 Date: $Date: 2008-03-26 22:30:34 $
7 Version: $Revision: 1.5 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmInstallCommandArguments.h"
18 #include "cmSystemTools.h"
20 // Table of valid permissions.
21 const char* cmInstallCommandArguments::PermissionsTable[] =
23 "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE",
24 "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE",
25 "WORLD_READ", "WORLD_WRITE", "WORLD_EXECUTE",
26 "SETUID", "SETGID", 0
29 const std::string cmInstallCommandArguments::EmptyString;
31 cmInstallCommandArguments::cmInstallCommandArguments()
32 :Parser()
33 ,ArgumentGroup()
34 ,Destination (&Parser, "DESTINATION" , &ArgumentGroup)
35 ,Component (&Parser, "COMPONENT" , &ArgumentGroup)
36 ,Rename (&Parser, "RENAME" , &ArgumentGroup)
37 ,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup)
38 ,Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
39 ,Optional (&Parser, "OPTIONAL" , &ArgumentGroup)
40 ,NamelinkOnly (&Parser, "NAMELINK_ONLY" , &ArgumentGroup)
41 ,NamelinkSkip (&Parser, "NAMELINK_SKIP" , &ArgumentGroup)
42 ,GenericArguments(0)
45 const std::string& cmInstallCommandArguments::GetDestination() const
47 if (!this->DestinationString.empty())
49 return this->DestinationString;
51 if (this->GenericArguments!=0)
53 return this->GenericArguments->GetDestination();
55 return this->EmptyString;
58 const std::string& cmInstallCommandArguments::GetComponent() const
60 if (!this->Component.GetString().empty())
62 return this->Component.GetString();
64 if (this->GenericArguments!=0)
66 return this->GenericArguments->GetComponent();
69 static std::string unspecifiedComponent = "Unspecified";
70 return unspecifiedComponent;
73 const std::string& cmInstallCommandArguments::GetRename() const
75 if (!this->Rename.GetString().empty())
77 return this->Rename.GetString();
79 if (this->GenericArguments!=0)
81 return this->GenericArguments->GetRename();
83 return this->EmptyString;
86 const std::string& cmInstallCommandArguments::GetPermissions() const
88 if (!this->PermissionsString.empty())
90 return this->PermissionsString;
92 if (this->GenericArguments!=0)
94 return this->GenericArguments->GetPermissions();
96 return this->EmptyString;
99 bool cmInstallCommandArguments::GetOptional() const
101 if (this->Optional.IsEnabled())
103 return true;
105 if (this->GenericArguments!=0)
107 return this->GenericArguments->GetOptional();
109 return false;
112 bool cmInstallCommandArguments::GetNamelinkOnly() const
114 if (this->NamelinkOnly.IsEnabled())
116 return true;
118 if (this->GenericArguments!=0)
120 return this->GenericArguments->GetNamelinkOnly();
122 return false;
125 bool cmInstallCommandArguments::GetNamelinkSkip() const
127 if (this->NamelinkSkip.IsEnabled())
129 return true;
131 if (this->GenericArguments!=0)
133 return this->GenericArguments->GetNamelinkSkip();
135 return false;
138 const std::vector<std::string>&
139 cmInstallCommandArguments::GetConfigurations() const
141 if (!this->Configurations.GetVector().empty())
143 return this->Configurations.GetVector();
145 if (this->GenericArguments!=0)
147 return this->GenericArguments->GetConfigurations();
149 return this->Configurations.GetVector();
153 bool cmInstallCommandArguments::Finalize()
155 if (!this->CheckPermissions())
157 return false;
159 this->DestinationString = this->Destination.GetString();
160 cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
161 return true;
164 void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
165 std::vector<std::string>* unconsumedArgs)
167 this->Parser.Parse(args, unconsumedArgs);
171 bool cmInstallCommandArguments::CheckPermissions()
173 this->PermissionsString = "";
174 for(std::vector<std::string>::const_iterator
175 permIt = this->Permissions.GetVector().begin();
176 permIt != this->Permissions.GetVector().end();
177 ++permIt)
179 if (!this->CheckPermissions(*permIt, this->PermissionsString))
181 return false;
184 return true;
187 bool cmInstallCommandArguments::CheckPermissions(
188 const std::string& onePermission, std::string& permissions)
190 // Check the permission against the table.
191 for(const char** valid = cmInstallCommandArguments::PermissionsTable;
192 *valid; ++valid)
194 if(onePermission == *valid)
196 // This is a valid permission.
197 permissions += " ";
198 permissions += onePermission;
199 return true;
202 // This is not a valid permission.
203 return false;