Пример #1
0
dmz::Config
dmz::QtCanvasViewSession::get_config () {

   String val;
   Config session ("canvasView");

   val.flush () << _canvas.get_scale ();
   session.store_attribute ("scale", val);

   val.flush () << _canvas.width ();
   session.store_attribute ("width", val);

   val.flush () << _canvas.height ();
   session.store_attribute ("height", val);

   Config scrollBars ("scrollBars");

   val.flush () << _canvas.verticalScrollBar ()->value ();
   scrollBars.store_attribute ("vertical", val);

   val.flush () << _canvas.horizontalScrollBar ()->value ();
   scrollBars.store_attribute ("horizontal", val);

   session.add_config (scrollBars);

   return session;
}
Пример #2
0
/*!

\brief Finds absolute path.
\details Defined in dmzSystemFile.h.
\param[in] Path String containing path used to find the absolute (a.k.a. canonical) path
\param[out] absPath String in which the found absolute path is stored.
\return Returns dmz::True if absolute path is found.

*/
dmz::Boolean
dmz::get_absolute_path (const String &Path, String &absPath) {

   Boolean result (False);

   if (is_valid_path (Path)) {

      if (is_directory (Path)) {

         const PushDirectory Push (Path);

         if (Push.is_valid ()) { result = True; absPath = get_current_directory (); }
      }
      else {

         String spath, file, ext;
         split_path_file_ext (Path, spath, file, ext);

         if (!spath) { spath = "."; }

         const PushDirectory Push (spath);

         if (Push.is_valid ()) {

            result = True;
            absPath.flush () <<  get_current_directory () << file << ext;
         }
      }

      absPath = format_path (absPath);
   }
   else { absPath.flush (); }

   return result;
}
Пример #3
0
/*!

\brief Gets the current value store in the config context.
\param[out] value String used to store the config context value.
\return Returns dmz::True if the config context value was stored in \a value.

*/
dmz::Boolean
dmz::Config::get_value (String &value) const {

   Boolean result (False);

   if (_state.context) {

      if (!_state.context->Name) {

         ConfigAttributeContext *at (_state.context->attrTable.lookup (""));

         if (at) {

            result = True;

            at->lock.lock ();
               value.flush () << at->value;
            at->lock.unlock ();
          }
      }
      else {

         ConfigContext::DataList *dl (_state.context->configTable.lookup (""));

         if (dl) {

            result = True;

            value.flush ();
            dl->lock.lock ();
               ConfigContext::DataStruct *ds (dl->head);
               while (ds) {

                  if (ds->handle && ds->context) {

                     ConfigAttributeContext *at (ds->context->attrTable.lookup (""));

                     if (at) {

                        at->lock.lock ();
                           value << at->value;
                        at->lock.unlock ();
                     }
                  }

                  ds = ds->next;
               }
            dl->lock.unlock ();
         }
      }
   }

   return result;
}
Пример #4
0
void
TestObserver::update_current_undo_names (
      const String *NextUndoName,
      const String *NextRedoName) {

   if (NextUndoName) { undoName = *NextUndoName; }
   else { undoName.flush (); }

   if (NextRedoName) { redoName = *NextRedoName; }
   else { redoName.flush (); }
}
   Boolean zip_error (const int Err) {

      Boolean result (Err == ZIP_OK ? True : False);

      if (!result) {

         if (Err == ZIP_ERRNO) { error.flush () << strerror (errno); }
         else if (Err == ZIP_PARAMERROR) { error.flush () << "Parameter Error."; }
         else if (Err == ZIP_BADZIPFILE) { error.flush () << "Bad Zip File."; }
         else if (Err == ZIP_INTERNALERROR) { error.flush () << "Internal Zip Error."; }
         else { error.flush () << "Unknown Zip Error."; }
      }

      return result;
   }
Пример #6
0
/*!

\brief Creates a directory.
\details Defined in dmzSystemFile.h. Function will create a path as deep as is
requested in \a Path. Function returns dmz::True if path already exists.
\param[in] Path String containing directory to create.
\return Returns dmz::True if directory was successfully created.

*/
dmz::Boolean
dmz::create_directory (const String &Path) {

   Boolean result (False);

   if (Path) {

      result = True;
      const String FormattedPath (format_path (Path));
      StringTokenizer st (FormattedPath, '/');
      String dir;
      if (FormattedPath.get_char (0) == '/') { dir << "/"; }
      String part (st.get_next ());

      while (part) {

         if (dir) { dir << "/" << part; }
         else { dir = part; }

         if (!is_valid_path (dir)) {

            if (mkdir (dir.get_buffer (), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {

               result = False;
            }
         }

         if (result) { part = st.get_next (); }
         else { part.flush (); }
      }
   }

   return result;
}
Пример #7
0
/*!

\brief Converts Vector to Config.
\details Defined in dmzRuntimeConfigWrite.h.
The Vector values are stored in three attributes named: "x", "y", and "z".
\note Unlike the config_to_* functions, the \a Name parameter can not be scoped.
The \a Name parameter should not contain "." characters.
\param[in] Name String containing name of config context to create.
\param[in] Value Vector to convert to Config.
\return Returns a Config object containing the converted Vector.

*/
dmz::Config
dmz::vector_to_config (
      const String &Name,
      const Vector &Value) {

   Config result (Name);

   String val;

   val << Value.get_x ();
   result.store_attribute ("x", val);

   val.flush () << Value.get_y ();
   result.store_attribute ("y", val);

   val.flush () << Value.get_z ();
   result.store_attribute ("z", val);

   return result;
}
Пример #8
0
/*!

\brief Gets state names.
\param[in] State Mask containing states to be named.
\param[out] name String to store found state names.
\return Returns dmz::True if all the states stored in \a State have names.
\note This function will find the names for as many states as possible. If the \a State
mask contains more than one state, the names are separated by the "|" character
(a.k.a. bitwise or operator).

*/
dmz::Boolean
dmz::Definitions::lookup_state_name (const Mask &State, String &name) const {

   Boolean result (False);

   Mask maskCopy (State);

   if (_state.defs) {

      name.flush ();

      HashTableStringIterator it;

      Mask *ptr = _state.defs->maskTable.get_first (it);

      while (ptr) {

         if (State & *ptr) {

            if (!name) { name = it.get_hash_key (); }
            else { name << " | " << it.get_hash_key (); }

            maskCopy.unset (*ptr);
         }

         ptr = _state.defs->maskTable.get_next (it);
      }

      if (!maskCopy) { result = True; }
      else if (_state.log) {

         _state.log->error << "Unidentified state bits in: " << name << endl;
            // << ", unknown bits: " << maskCopy << endl;
      }
   }

   return result;
}
Пример #9
0
/*!

\brief Splits a path into the directory, file name, and file extension.
\ingroup System
\details Defined in dmzSystemFile.h.
The \a FullPath is formatted before processing. The file extension is returned with
the leading period. If either a path or extension is not found in the \a FullPath,
the corresponding return value is an empty string.
\param[in] FullPath String containing full path to be split up.
\param[out] path String containing the directory component of the \a FullPath.
\param[out] file String containing the file component of the \a FullPath.
\param[out] ext String containing the extension of the \a FullPath.

*/
void
dmz::split_path_file_ext (
    const String &FullPath,
    String &path,
    String &file,
    String &ext) {

    path = format_path (FullPath);
    file.flush ();
    ext.flush ();

    const Int32 Length = path.get_length ();

    Int32 slashFound = -1;
    Int32 index = Length - 1;

    Boolean done (False);

    while (!done) {

        if (path.get_char (index) == '/') {
            slashFound = index;
            done = True;
        }
        else {
            index--;
            if (index < 0) {
                done = True;
            }
        }
    }

    if (slashFound >= 0) {

        file = path.get_sub (slashFound + 1);
        path = path.get_sub (0, slashFound);
    }
    else {

        file = path;
        path.flush ();
    }

    if (file) {

        const Int32 FileLength = file.get_length ();
        Int32 dotFound = -1;

        index = FileLength - 1;
        done = False;

        while (!done) {

            if (file.get_char (index) == '.') {
                dotFound = index;
                done = True;
            }
            else {
                index--;
                if (index < 0) {
                    done = True;
                }
            }
        }

        if (dotFound > 0) {

            ext = file.get_sub (dotFound);
            file = file.get_sub (0, dotFound - 1);
        }
    }
}
Пример #10
0
   void clear () {

      index = -1;
      key.flush ();
      growCount = 0;
   }
Пример #11
0
/*!

\brief Look up a dmz::String from an attribute element.
\param[in] AttrHandle Attribute handle.
\param[in] Element Index of attribute element.
\param[out] value Variable to be returned.
\return Returns dmz::True if the element was successfully retrieved.

*/
dmz::Boolean
dmz::Data::lookup_string (
      const Handle AttrHandle,
      const Int32 Element,
      String &value) const {

   Boolean result (False);

   dataStruct *ds = _state.get_data (AttrHandle);

   if (ds) {

      const BaseTypeEnum Type = ds->Attr.Type;

      if (Type == BaseTypeString) {

         UInt32 strHandle (ds->lookup_string_handle (Element));

         if (strHandle && _state.stringTable) {

            String *ptr = _state.stringTable->table.lookup (strHandle);

            if (ptr) { value = *ptr; result = True; }
         }

         if (!result) {

            const Int32 AtSize (ds->Attr.Size);

            if ((Element >= 0) && ((Element < AtSize) || (AtSize == 0))) {

               value.flush () << "";
               result = True;
            }
         }
      }
      else if (Type == BaseTypeFloat64) {

         Float64 converted (0.0);
         result = float64Convert.read (*ds, Element, _state.stringTable, converted);
         value.flush () << converted;
      }
      else if (Type == BaseTypeFloat32) {

         Float32 converted (0.0f);
         result = float32Convert.read (*ds, Element, _state.stringTable, converted);
         value.flush () << converted;
      }
      else if (Type == BaseTypeInt32) {

         Int32 converted (0);
         result = int32Convert.read (*ds, Element, _state.stringTable, converted);
         value.flush () << converted;
      }
      else if (Type == BaseTypeUInt32) {

         UInt32 converted (0);
         result = uint32Convert.read (*ds, Element, _state.stringTable, converted);
         value.flush () << converted;
      }
      else if (Type == BaseTypeInt64) {

         Int64 converted (0);
         result = int64Convert.read (*ds, Element, _state.stringTable, converted);
         value.flush () << converted;
      }
      else if (Type == BaseTypeUInt64) {

         UInt64 converted (0);
         result = uint64Convert.read (*ds, Element, _state.stringTable, converted);
         value.flush () << converted;
      }
   }

   return result;
}