packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmListCommand.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmListCommand_h
13 #define cmListCommand_h
14
15 #include "cmCommand.h"
16
17 /** \class cmListCommand
18  * \brief Common list operations
19  *
20  */
21 class cmListCommand : public cmCommand
22 {
23 public:
24   /**
25    * This is a virtual constructor for the command.
26    */
27   virtual cmCommand* Clone()
28     {
29     return new cmListCommand;
30     }
31
32   /**
33    * This is called when the command is first encountered in
34    * the CMakeLists.txt file.
35    */
36   virtual bool InitialPass(std::vector<std::string> const& args,
37                            cmExecutionStatus &status);
38
39   /**
40    * This determines if the command is invoked when in script mode.
41    */
42   virtual bool IsScriptable() const { return true; }
43
44   /**
45    * The name of the command as specified in CMakeList.txt.
46    */
47   virtual const char* GetName() const { return "list";}
48
49   /**
50    * Succinct documentation.
51    */
52   virtual const char* GetTerseDocumentation() const
53     {
54     return "List operations.";
55     }
56
57   /**
58    * More documentation.
59    */
60   virtual const char* GetFullDocumentation() const
61     {
62     return
63       "  list(LENGTH <list> <output variable>)\n"
64       "  list(GET <list> <element index> [<element index> ...]\n"
65       "       <output variable>)\n"
66       "  list(APPEND <list> <element> [<element> ...])\n"
67       "  list(FIND <list> <value> <output variable>)\n"
68       "  list(INSERT <list> <element_index> <element> [<element> ...])\n"
69       "  list(REMOVE_ITEM <list> <value> [<value> ...])\n"
70       "  list(REMOVE_AT <list> <index> [<index> ...])\n"
71       "  list(REMOVE_DUPLICATES <list>)\n"
72       "  list(REVERSE <list>)\n"
73       "  list(SORT <list>)\n"
74       "LENGTH will return a given list's length.\n"
75       "GET will return list of elements specified by indices from the list.\n"
76       "APPEND will append elements to the list.\n"
77       "FIND will return the index of the element specified in the list or -1 "
78       "if it wasn't found.\n"
79       "INSERT will insert elements to the list to the specified location.\n"
80       "REMOVE_AT and REMOVE_ITEM will remove items from the list. The "
81       "difference is that REMOVE_ITEM will remove the given items, while "
82       "REMOVE_AT will remove the items at the given indices.\n"
83       "REMOVE_DUPLICATES will remove duplicated items in the list.\n"
84       "REVERSE reverses the contents of the list in-place.\n"
85       "SORT sorts the list in-place alphabetically.\n"
86       "The list subcommands APPEND, INSERT, REMOVE_AT, REMOVE_ITEM, "
87       "REMOVE_DUPLICATES, REVERSE and SORT may create new values for "
88       "the list within the current CMake variable scope. Similar to "
89       "the SET command, the LIST command creates new variable values "
90       "in the current scope, even if the list itself is actually "
91       "defined in a parent scope. To propagate the results of these "
92       "operations upwards, use SET with PARENT_SCOPE, SET with CACHE "
93       "INTERNAL, or some other means of value propagation.\n"
94       "NOTES: A list in cmake is a ; separated group of strings. "
95       "To create a list the set command can be used. For example, "
96       "set(var a b c d e)  creates a list with a;b;c;d;e, and "
97       "set(var \"a b c d e\") creates a string or a list with one "
98       "item in it.\n"
99       "When specifying index values, if <element index> is 0 or"
100       " greater, it is indexed from the "
101       "beginning of the list, with 0 representing the first list element. "
102       "If <element index> is -1 or lesser, it is indexed from the end of "
103       "the list, with -1 representing the last list element. Be careful "
104       "when counting with negative indices: they do not start from 0. "
105       "-0 is equivalent to 0, the first list element.\n"
106       ;
107     }
108
109   cmTypeMacro(cmListCommand, cmCommand);
110 protected:
111   bool HandleLengthCommand(std::vector<std::string> const& args);
112   bool HandleGetCommand(std::vector<std::string> const& args);
113   bool HandleAppendCommand(std::vector<std::string> const& args);
114   bool HandleFindCommand(std::vector<std::string> const& args);
115   bool HandleInsertCommand(std::vector<std::string> const& args);
116   bool HandleRemoveAtCommand(std::vector<std::string> const& args);
117   bool HandleRemoveItemCommand(std::vector<std::string> const& args);
118   bool HandleRemoveDuplicatesCommand(std::vector<std::string> const& args);
119   bool HandleSortCommand(std::vector<std::string> const& args);
120   bool HandleReverseCommand(std::vector<std::string> const& args);
121
122
123   bool GetList(std::vector<std::string>& list, const char* var);
124   bool GetListString(std::string& listString, const char* var);
125 };
126
127
128 #endif