Panda3D

findApproxPath.h

00001 // Filename: FindApproxPath.h
00002 // Created by:  drose (13Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef FINDAPPROXPATH_H
00016 #define FINDAPPROXPATH_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "globPattern.h"
00021 #include "typeHandle.h"
00022 #include "pvector.h"
00023 
00024 class PandaNode;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : FindApproxPath
00028 // Description : This class is local to this package only; it doesn't
00029 //               get exported.  It chops a string path, as supplied to
00030 //               find_up() or find_down(), and breaks it up into its
00031 //               component pieces.
00032 ////////////////////////////////////////////////////////////////////
00033 class FindApproxPath {
00034 public:
00035   INLINE FindApproxPath();
00036 
00037   bool add_string(const string &str_path);
00038   bool add_flags(const string &str_flags);
00039   bool add_component(string str_component);
00040 
00041   void add_match_name(const string &name, int flags);
00042   void add_match_name_glob(const string &glob, int flags);
00043   void add_match_exact_type(TypeHandle type, int flags);
00044   void add_match_inexact_type(TypeHandle type, int flags);
00045   void add_match_tag(const string &key, int flags);
00046   void add_match_tag_value(const string &key, const string &value, int flags);
00047   
00048   void add_match_one(int flags);
00049   void add_match_many(int flags);
00050   void add_match_pointer(PandaNode *pointer, int flags);
00051 
00052   INLINE int get_num_components() const;
00053   INLINE bool is_component_match_many(int index) const;
00054   INLINE bool matches_component(int index, PandaNode *node) const;
00055   INLINE bool matches_stashed(int index) const;
00056 
00057   INLINE bool return_hidden() const;
00058   INLINE bool return_stashed() const;
00059   INLINE bool case_insensitive() const;
00060 
00061   void output(ostream &out) const;
00062   INLINE void output_component(ostream &out, int index) const;
00063 
00064 #if !defined(WIN32_VC) && !defined(WIN64_VC)
00065 // Visual C++ won't let us define the ostream operator functions for
00066 // these guys if they're private--even though we declare them friends.
00067 private:
00068 #endif
00069   enum ComponentType {
00070     CT_match_name,
00071     CT_match_name_insensitive,
00072     CT_match_name_glob,
00073     CT_match_exact_type,
00074     CT_match_inexact_type,
00075     CT_match_tag,
00076     CT_match_tag_value,
00077     CT_match_one,
00078     CT_match_many,
00079     CT_match_pointer
00080   };
00081   enum ComponentFlags {
00082     CF_stashed        = 0x001,
00083   };
00084 
00085   class Component {
00086   public:
00087     bool matches(PandaNode *node) const;
00088     void output(ostream &out) const;
00089 
00090     ComponentType _type;
00091     string _name;
00092     GlobPattern _glob;
00093     TypeHandle _type_handle;
00094     PandaNode *_pointer;
00095     int _flags;
00096   };
00097 
00098   typedef pvector<Component> Path;
00099   Path _path;
00100 
00101   bool _return_hidden;
00102   bool _return_stashed;
00103   bool _case_insensitive;
00104 
00105 friend ostream &operator << (ostream &, FindApproxPath::ComponentType);
00106 friend INLINE ostream &operator << (ostream &, const FindApproxPath::Component &);
00107 };
00108 
00109 ostream &
00110 operator << (ostream &out, FindApproxPath::ComponentType type);
00111 
00112 INLINE ostream &
00113 operator << (ostream &out, const FindApproxPath::Component &component) {
00114   component.output(out);
00115   return out;
00116 }
00117 
00118 INLINE ostream &
00119 operator << (ostream &out, const FindApproxPath &path) {
00120   path.output(out);
00121   return out;
00122 }
00123 
00124 #include "findApproxPath.I"
00125 
00126 #endif
 All Classes Functions Variables Enumerations