text: //! \file
  //! \brief Manages set of scripts used by all drones in an instance of a game
  //!
  //! Primary Author:  Dylan Leeman
  //! Contributing Author:  Aaron Weeden
  
  #ifndef AUTONOMY_SCRIPT_LIBRARY_HPP
  #define AUTONOMY_SCRIPT_LIBRARY_HPP
  
  #include <map>
  #include <utility>
  #include <string>
  #include <iostream>
  #include <vector>
  
  #include <boost/shared_ptr.hpp>
  #include <boost/thread/shared_mutex.hpp>
  
  #include <autonomy/script_object.hpp>
  
  namespace autonomy
  {
  
      template < typename ParentT >
      class script_library
      {
          friend class boost::serialization::access;
          private:
              typedef std::map< script_object_id_t,
                               boost::shared_ptr< script_object > >
              _script_store_t;
          public:
              script_library()
              {}
  
              ParentT & parent()
              {
                  return *static_cast< ParentT* >(this);
              }
              const ParentT & parent() const
              {
                  return *static_cast< ParentT* >(this);
              }
  
  
              //! Create a new script, with an optional name, returns id of the
              //! new script
              script_object_id_t new_script(std::string name = std::string());
  
              //! Get the name of a script, given its handle
              std::string fetch_name( script_object_id_t script ) const;
  
              //! Set the raw form of a script in the library
              bool set_script( script_object_id_t script, 
                               std::string text = std::string() );
  
              //! Read a script directly from an istream
              bool read_script( script_object_id_t script,
                                std::istream & is );
  
              //! Rename a script, given an id and name, returns true if
              //! successful
              bool rename_script ( script_object_id_t script, std::string name );
  
              //! Replace the raw text of a script, given an id and a string, 
              //! returns true if successful
              bool replace_script( script_object_id_t script, 
                                   const std::string & text );
  
              //! Deletes a script_object from the library
              void delete_script( script_object_id_t script );
  
              //! (Re-)Compile a script, returns a string with any error messages 
              //! generated by the compiler
              std::string compile_script( script_object_id_t script );
  
  
              //! Retrieve a handle to the compiled form of a script object,
              //! returns a default constructed shared_ptr on failure
              boost::shared_ptr<instruction_list> 
                  fetch_compiled_script( script_object_id_t script ) const;
  
              //! Return a vector of pairs that contains all scripts by name and
              //! id to the user.
              std::vector< std::pair < script_object_id_t, std::string > >
              fetch_scripts( ) const;
  
          private:
              _script_store_t _script_store;
              mutable boost::shared_mutex _script_store_mutex;
  
              template < class Archive >
                  void serialize( Archive & ar, const unsigned int version )
                  {
                      ar & BOOST_SERIALIZATION_NVP(_script_store);
                  }
      };
  }
  
  #include <autonomy/script_library.inc.cpp>
  #endif
  