Home | History | Annotate | Download | only in parameter
      1 /*
      2  * Copyright (c) 2011-2014, Intel Corporation
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without modification,
      6  * are permitted provided that the following conditions are met:
      7  *
      8  * 1. Redistributions of source code must retain the above copyright notice, this
      9  * list of conditions and the following disclaimer.
     10  *
     11  * 2. Redistributions in binary form must reproduce the above copyright notice,
     12  * this list of conditions and the following disclaimer in the documentation and/or
     13  * other materials provided with the distribution.
     14  *
     15  * 3. Neither the name of the copyright holder nor the names of its contributors
     16  * may be used to endorse or promote products derived from this software without
     17  * specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
     23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 #pragma once
     31 
     32 #include "Parameter.h"
     33 
     34 class CArrayParameter : public CParameter
     35 {
     36 public:
     37     CArrayParameter(const std::string &strName, const CTypeElement *pTypeElement);
     38 
     39     // Instantiation, allocation
     40     virtual size_t getFootPrint() const;
     41 
     42     /// Value access
     43     using CBaseParameter::access;
     44     bool access(std::vector<bool> &abValues, bool bSet,
     45                 CParameterAccessContext &parameterAccessContext) const override final;
     46     bool access(std::vector<uint32_t> &auiValues, bool bSet,
     47                 CParameterAccessContext &parameterAccessContext) const override final;
     48     bool access(std::vector<int32_t> &aiValues, bool bSet,
     49                 CParameterAccessContext &parameterAccessContext) const override final;
     50     bool access(std::vector<double> &adValues, bool bSet,
     51                 CParameterAccessContext &parameterAccessContext) const override final;
     52     bool access(std::vector<std::string> &astrValues, bool bSet,
     53                 CParameterAccessContext &parameterAccessContext) const override final;
     54 
     55 protected:
     56     // User set/get
     57     virtual bool accessValue(CPathNavigator &pathNavigator, std::string &strValue, bool bSet,
     58                              CParameterAccessContext &parameterAccessContext) const;
     59     // Used for simulation and virtual subsystems
     60     virtual void setDefaultValues(CParameterAccessContext &parameterAccessContext) const;
     61 
     62     // Element properties
     63     virtual void showProperties(std::string &strResult) const;
     64 
     65 private:
     66     // Array length
     67     size_t getArrayLength() const;
     68     // Common set value processing
     69     bool setValues(size_t uiStartIndex, size_t offset, const std::string &strValue,
     70                    CParameterAccessContext &parameterAccessContext) const;
     71     // Log / get values common
     72     std::string getValues(size_t baseOffset, CParameterAccessContext &parameterAccessContext) const;
     73     std::string logValue(CParameterAccessContext &context) const override;
     74     // Index retrieval from user set/get request
     75     bool getIndex(CPathNavigator &pathNavigator, size_t &index,
     76                   CParameterAccessContext &parameterAccessContext) const;
     77 
     78     /** Access whole array.
     79      *
     80      * @param[in] offset Offset of the array in the context blackboard.
     81      * @{
     82      */
     83     bool doSetValue(const std::string &strValue, size_t offset,
     84                     CParameterAccessContext &parameterAccessContext) const override;
     85     void doGetValue(std::string &strValue, size_t offset,
     86                     CParameterAccessContext &parameterAccessContext) const override;
     87     /** @} */
     88 
     89     /// Value access
     90     // Generic Access
     91     template <typename type>
     92     bool accessValues(std::vector<type> &values, bool bSet,
     93                       CParameterAccessContext &parameterAccessContext) const;
     94     template <typename type>
     95     bool setValues(const std::vector<type> &values,
     96                    CParameterAccessContext &parameterAccessContext) const;
     97     template <typename type>
     98     bool getValues(std::vector<type> &values,
     99                    CParameterAccessContext &parameterAccessContext) const;
    100     template <typename type>
    101     bool doSet(type value, size_t offset, CParameterAccessContext &parameterAccessContext) const;
    102     template <typename type>
    103     bool doGet(type &value, size_t offset, CParameterAccessContext &parameterAccessContext) const;
    104 };
    105