Aegis  4.25.D505
common/str_list.h
Go to the documentation of this file.
00001 //
00002 //      aegis - project change supervisor
00003 //      Copyright (C) 1991-1994, 1996, 1997, 2003-2006, 2008 Peter Miller
00004 //
00005 //      This program is free software; you can redistribute it and/or modify
00006 //      it under the terms of the GNU General Public License as published by
00007 //      the Free Software Foundation; either version 3 of the License, or
00008 //      (at your option) any later version.
00009 //
00010 //      This program is distributed in the hope that it will be useful,
00011 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //      GNU General Public License for more details.
00014 //
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program. If not, see
00017 //      <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #ifndef COMMON_STR_LIST_H
00021 #define COMMON_STR_LIST_H
00022 
00023 #include <common/str.h>
00024 
00035 class string_list_ty
00036 {
00037 public:
00041     ~string_list_ty();
00042 
00047     string_list_ty();
00048 
00052     string_list_ty(const string_list_ty &);
00053 
00057     string_list_ty &operator=(const string_list_ty &);
00058 
00068     bool member(string_ty *arg) const;
00069 
00080     bool member_nocase(string_ty *arg) const;
00081 
00086     size_t size() const { return nstrings; }
00087 
00096     bool empty() const { return (nstrings == 0); }
00097 
00102     string_ty *operator[](size_t n) const { return string[n]; }
00103 
00121     string_ty *unsplit(size_t start, size_t finish, const char *sep) const;
00122 
00136     string_ty *unsplit(const char *sep = 0) const;
00137 
00148     void push_front(string_ty *arg);
00149 
00159     void push_front(const string_list_ty &arg);
00160 
00168     void push_back(string_ty *arg);
00169 
00178     void push_back_unique(string_ty *arg);
00179 
00187     void push_back(const string_list_ty &arg);
00188 
00196     void push_back_unique(const string_list_ty &arg);
00197 
00213     void split(string_ty *arg, const char *sep = 0, bool white = false);
00214 
00223     void remove(string_ty *arg);
00224 
00233     void remove(const string_list_ty &arg);
00234 
00239     void clear();
00240 
00245     string_ty *front() { return (nstrings ? string[0] : 0); }
00246 
00251     string_ty *back() { return (nstrings ? string[nstrings - 1] : 0); }
00252 
00257     void pop_front();
00258 
00263     void pop_back();
00264 
00273     bool equal(const string_list_ty &arg) const;
00274 
00288     bool subset(const string_list_ty &arg) const;
00289 
00295     void sort();
00296 
00302     void sort_nocase();
00303 
00309     void sort_version();
00310 
00315     string_list_ty quote_shell() const;
00316 
00324     bool validate() const;
00325 
00331     string_list_ty intersection(const string_list_ty &rhs) const;
00332 
00333 // private:
00334     size_t nstrings;
00335     size_t nstrings_max;
00336     string_ty **string;
00337 };
00338 
00343 inline DEPRECATED int
00344 string_list_member(const string_list_ty *slp, string_ty *s)
00345 {
00346     return slp->member(s);
00347 }
00348 
00364 inline DEPRECATED string_ty *
00365 wl2str(const string_list_ty *slp, int start, int finish, const char *sep)
00366 {
00367     return slp->unsplit(start, finish, sep);
00368 }
00369 
00388 inline DEPRECATED void
00389 str2wl(string_list_ty *slp, string_ty *arg, const char *sep, int white)
00390 {
00391     slp->split(arg, sep, white);
00392 }
00393 
00403 inline DEPRECATED void
00404 string_list_prepend(string_list_ty *lhs, string_ty *rhs)
00405 {
00406     lhs->push_front(rhs);
00407 }
00408 
00418 inline DEPRECATED void
00419 string_list_prepend_list(string_list_ty *lhs, const string_list_ty *rhs)
00420 {
00421     lhs->push_front(*rhs);
00422 }
00423 
00433 inline DEPRECATED void
00434 string_list_append(string_list_ty *lhs, string_ty *rhs)
00435 {
00436     lhs->push_back(rhs);
00437 }
00438 
00448 inline DEPRECATED void
00449 string_list_append_list(string_list_ty *lhs, const string_list_ty *rhs)
00450 {
00451     lhs->push_back(*rhs);
00452 }
00453 
00464 inline DEPRECATED void
00465 string_list_append_unique(string_list_ty *lhs, string_ty *rhs)
00466 {
00467     lhs->push_back_unique(rhs);
00468 }
00469 
00480 inline DEPRECATED void
00481 string_list_append_list_unique(string_list_ty *lhs, const string_list_ty *rhs)
00482 {
00483     lhs->push_back_unique(*rhs);
00484 }
00485 
00492 inline DEPRECATED void
00493 string_list_copy(string_list_ty *lhs, const string_list_ty *rhs)
00494 {
00495     *lhs = *rhs;
00496 }
00497 
00504 inline DEPRECATED void
00505 string_list_remove(string_list_ty *slp, string_ty *s)
00506 {
00507     slp->remove(s);
00508 }
00509 
00519 inline DEPRECATED void
00520 string_list_remove_list(string_list_ty *lhs, const string_list_ty *rhs)
00521 {
00522     lhs->remove(*rhs);
00523 }
00524 
00530 inline DEPRECATED void
00531 string_list_destructor(string_list_ty *slp)
00532 {
00533     // from context, this is the right thing to do,
00534     // now that the real destructor does something useful.
00535     slp->clear();
00536 }
00537 
00543 inline DEPRECATED void
00544 string_list_constructor(string_list_ty *slp)
00545 {
00546     // from context, this is the right thing to do,
00547     // now that the real constructor does something useful.
00548     slp->clear();
00549 }
00550 
00560 inline bool
00561 operator==(const string_list_ty &lhs, const string_list_ty &rhs)
00562 {
00563     return lhs.equal(rhs);
00564 }
00565 
00566 
00576 inline bool
00577 operator!=(const string_list_ty &lhs, const string_list_ty &rhs)
00578 {
00579     return !lhs.equal(rhs);
00580 }
00581 
00590 inline DEPRECATED int
00591 string_list_subset(const string_list_ty *lhs, const string_list_ty *rhs)
00592 {
00593     return lhs->subset(*rhs);
00594 }
00595 
00601 inline DEPRECATED void
00602 string_list_sort(string_list_ty *slp)
00603 {
00604     slp->sort();
00605 }
00606 
00617 inline DEPRECATED void
00618 string_list_quote_shell(string_list_ty *lhs, const string_list_ty *rhs)
00619 {
00620     *lhs = rhs->quote_shell();
00621 }
00622 
00627 inline void
00628 operator+=(string_list_ty &lhs, const string_list_ty &rhs)
00629 {
00630     lhs.push_back_unique(rhs);
00631 }
00632 
00637 inline string_list_ty
00638 operator+(const string_list_ty &lhs, const string_list_ty &rhs)
00639 {
00640     string_list_ty result;
00641     result.push_back_unique(lhs);
00642     result.push_back_unique(rhs);
00643     return result;
00644 }
00645 
00650 inline void
00651 operator-=(string_list_ty &lhs, const string_list_ty &rhs)
00652 {
00653     lhs.remove(rhs);
00654 }
00655 
00660 inline string_list_ty
00661 operator-(const string_list_ty &lhs, const string_list_ty &rhs)
00662 {
00663     string_list_ty result;
00664     result.push_back_unique(lhs);
00665     result.remove(rhs);
00666     return result;
00667 }
00668 
00673 inline void
00674 operator*=(string_list_ty &lhs, const string_list_ty &rhs)
00675 {
00676     lhs = lhs.intersection(rhs);
00677 }
00678 
00683 inline string_list_ty
00684 operator*(const string_list_ty &lhs, const string_list_ty &rhs)
00685 {
00686     return lhs.intersection(rhs);
00687 }
00688 
00690 #endif // COMMON_STR_LIST_H