home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / scripting.h < prev    next >
C/C++ Source or Header  |  2008-11-07  |  3KB  |  97 lines

  1. #ifndef K3DSDK_SCRIPTING_H
  2. #define K3DSDK_SCRIPTING_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2008, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. /** \file
  24.     \author Tim Shead (tshead@k-3d.com)
  25. */
  26.  
  27. #include "iscript_engine.h"
  28. #include "types.h"
  29.  
  30. #include <iosfwd>
  31.  
  32. namespace k3d
  33. {
  34.  
  35. class iplugin_factory;
  36. class uuid;
  37.  
  38. namespace filesystem { class path; }
  39. namespace mime { class type; }
  40.  
  41. namespace script
  42. {
  43.  
  44. /// Helper class that converts various forms of input into script code that can be executed
  45. class code
  46. {
  47. public:
  48.     /// Script code is stored as a string
  49.     code(const string_t& Source);
  50.     /// Script code is stored as an input stream
  51.     code(std::istream& Source);
  52.     /// Script code is stored in a string stream
  53.     code(std::istringstream& Source);
  54.     /// Script code is stored in a string stream
  55.     code(std::stringstream& Source);
  56.  
  57.     /// Returns the stored script source code
  58.     const string_t& source() const;
  59.  
  60. private:
  61.     string_t m_buffer;
  62. };
  63.  
  64. /// Helper class that converts various forms of input into an identifiable script language
  65. class language
  66. {
  67. public:
  68.     /// Determine scripting language from a filesystem path
  69.     language(const filesystem::path& Script);
  70.     /// Determine the scripting language from the script sources
  71.     language(const code& Script);
  72.     /// Determine the scripting language from a MIME type
  73.     language(const mime::type& Type);
  74.     /// Specify the scripting language directly
  75.     language(const uuid& Language);
  76.     /// Specify the scripting language directly
  77.     language(iplugin_factory& Language);
  78.  
  79.     /// Returns the plugin factory that corresponds with the given scripting language
  80.     iplugin_factory* factory() const;
  81.  
  82. private:
  83.     iplugin_factory* m_factory;
  84. };
  85.  
  86. /// Executes a script using an explicitly-specified language
  87. bool execute(const code& Script, const string_t& ScriptName, iscript_engine::context_t& Context, const language& Language);
  88. /// Executes a script, attempting to automatically recognize the language
  89. void execute(const code& Script, const string_t& ScriptName, iscript_engine::context_t& Context, bool& Recognized, bool& Executed);
  90.  
  91. } // namespace script
  92.  
  93. } // namespace k3d
  94.  
  95. #endif // !K3DSDK_SCRIPTING_H
  96.  
  97.