/[svn]/linuxsampler/trunk/src/scriptvm/common.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/common.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2889 by schoenebeck, Mon Apr 25 17:28:23 2016 UTC revision 2942 by schoenebeck, Wed Jul 13 15:51:06 2016 UTC
# Line 553  namespace LinuxSampler { Line 553  namespace LinuxSampler {
553          VMInt8Array() : data(NULL), size(0) {}          VMInt8Array() : data(NULL), size(0) {}
554      };      };
555    
556        /** @brief Dynamically executed variable (abstract base class).
557         *
558         * Interface for the implementation of a dynamically generated content of
559         * a built-in script variable. Most built-in variables are simply pointers
560         * to some native location in memory. So when a script reads them, the
561         * memory location is simply read to get the value of the variable. A
562         * dynamic variable however is not simply a memory location. For each access
563         * to a dynamic variable some native code is executed to actually generate
564         * and provide the content (value) of this type of variable.
565         */
566        class VMDynVar : virtual public VMExpr {
567        public:
568            /**
569             * Whether a script may modify the content of this dynamic variable by
570             * assigning a new value to it.
571             *
572             * @see isConstExpr(), assign()
573             */
574            virtual bool isAssignable() const = 0;
575    
576            /**
577             * Returns true in case this dynamic variable can be considered to be a
578             * constant expression. A constant expression will retain the same value
579             * throughout the entire life time of a script and the expression's
580             * constant value may be evaluated already at script parse time, which
581             * may result in performance benefits during script runtime.
582             *
583             * However due to the "dynamic" behavior of dynamic variables, almost
584             * all dynamic variables are probably not constant expressions. That's
585             * why this method returns @c false by default. If you are really sure
586             * that your dynamic variable implementation can be considered a
587             * constant expression then you may override this method and return
588             * @c true instead. Note that when you return @c true here, your
589             * dynamic variable will really just be executed once; and exectly
590             * already when the script is loaded!
591             *
592             * As an example you may implement a "constant" built-in dynamic
593             * variable that checks for a certain operating system feature and
594             * returns the result of that OS feature check as content (value) of
595             * this dynamic variable. Since the respective OS feature might become
596             * available/unavailable after OS updates, software migration, etc. the
597             * OS feature check should at least be performed once each time the
598             * application is launched. And since the OS feature check might take a
599             * certain amount of execution time, it might make sense to only
600             * perform the check if the respective variable name is actually
601             * referenced at all in the script to be loaded. Note that the dynamic
602             * variable will still be evaluated again though if the script is
603             * loaded again. So it is up to you to probably cache the result in the
604             * implementation of your dynamic variable.
605             *
606             * On doubt, please rather consider to use a constant built-in script
607             * variable instead of implementing a "constant" dynamic variable, due
608             * to the runtime overhead a dynamic variable may cause.
609             *
610             * @see isAssignable()
611             */
612            virtual bool isConstExpr() const { return false; }
613    
614            /**
615             * In case this dynamic variable is assignable, the new value (content)
616             * to be assigned to this dynamic variable.
617             *
618             * By default this method does nothing. Override and implement this
619             * method in your subclass in case your dynamic variable allows to
620             * assign a new value by script.
621             *
622             * @param expr - new value to be assigned to this variable
623             */
624            virtual void assign(VMExpr* expr) {}
625        };
626    
627        /** @brief Dynamically executed variable (of integer data type).
628         *
629         * This is the base class for all built-in integer script variables whose
630         * variable content needs to be provided dynamically by executable native
631         * code on each script variable access.
632         */
633        class VMDynIntVar : virtual public VMDynVar, virtual public VMIntExpr {
634        public:
635        };
636    
637        /** @brief Dynamically executed variable (of string data type).
638         *
639         * This is the base class for all built-in string script variables whose
640         * variable content needs to be provided dynamically by executable native
641         * code on each script variable access.
642         */
643        class VMDynStringVar : virtual public VMDynVar, virtual public VMStringExpr {
644        public:
645        };
646    
647      /** @brief Provider for built-in script functions and variables.      /** @brief Provider for built-in script functions and variables.
648       *       *
649       * Abstract base class defining the high-level interface for all classes       * Abstract base class defining the high-level interface for all classes
# Line 587  namespace LinuxSampler { Line 678  namespace LinuxSampler {
678           * variables, which never change their value at runtime.           * variables, which never change their value at runtime.
679           */           */
680          virtual std::map<String,int> builtInConstIntVariables() = 0;          virtual std::map<String,int> builtInConstIntVariables() = 0;
681    
682            /**
683             * Returns a variable name indexed map of all built-in dynamic variables,
684             * which are not simply data stores, rather each one of them executes
685             * natively to provide or alter the respective script variable data.
686             */
687            virtual std::map<String,VMDynVar*> builtInDynamicVariables() = 0;
688      };      };
689    
690      /** @brief Execution state of a virtual machine.      /** @brief Execution state of a virtual machine.

Legend:
Removed from v.2889  
changed lines
  Added in v.2942

  ViewVC Help
Powered by ViewVC