- added attrByName() method
authorAleš Křenek <ljocha@ics.muni.cz>
Wed, 27 Feb 2008 12:45:31 +0000 (12:45 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Wed, 27 Feb 2008 12:45:31 +0000 (12:45 +0000)
- XXX: option to disable flesh free()ing

org.glite.lb.client/interface/JobStatus.h.T
org.glite.lb.client/src/JobStatus.cpp.T

index d8e1128..49a263b 100644 (file)
@@ -223,6 +223,13 @@ public:
         * \throws LoggingException Invalid attribute name.
         */
        static const std::string& getAttrName(Attr name);
+
+       /** Find attribute by name (case insensitive)
+        * \param[in] name String name.
+        * \returns enum attr value.
+        * \throws LoggingException Invalid attribute name.
+        */
+       static Attr attrByName(std::string const &);
   
        /** List of attributes and their types valid for this
         * instance.
@@ -271,8 +278,9 @@ public:
         *
         * Encapsulates the given struct.
         * \param[in] src C struct that holds the status.
+        * \param[in] destroy destroy src after use.
         */
-       JobStatus(const edg_wll_JobStat &src);
+       JobStatus(const edg_wll_JobStat &src,int destroy = 1);
 
         /** Assignment from the C type.
         *
index c2b3619..104cc44 100644 (file)
@@ -74,10 +74,11 @@ JobStatus::operator=(const JobStatus & in)
   return *this;
 }
 
-JobStatus::JobStatus(const edg_wll_JobStat & in)
+JobStatus::JobStatus(const edg_wll_JobStat & in,int destroy)
 {
   status = (Code)in.state;
   flesh = new CountRef<JobStatus>((void*)&in);
+  if (!destroy) flesh->use();
 }
  
 JobStatus & 
@@ -428,6 +429,16 @@ JobStatus::getAttrName(JobStatus::Attr attr)
   return attr_names[attr];
 }
 
+JobStatus::Attr JobStatus::attrByName(std::string const & name)
+{
+       int     a;
+       for (a=0; a<ATTR_MAX; a++) {
+               if (strcasecmp(attr_names[a].c_str(),name.c_str()) == 0) return (JobStatus::Attr) a;
+       }
+       STACK_ADD;
+       throw(Exception(EXCEPTION_MANDATORY,EINVAL,"no such attribute"));
+}
+
 
 typedef std::pair<JobStatus::Attr,JobStatus::AttrType> tpair;
 static std::vector<tpair> attrs;