Exemple #1
0
// StoreVariableString
//------------------------------------------------------------------------------
bool BFFParser::StoreVariableString( const AString & name,
									 const BFFIterator & valueStart, const BFFIterator & valueEnd,
									 const BFFIterator & operatorIter,
									 BFFStackFrame * frame )
{
	// unescape and subsitute embedded variables
	AStackString< 2048 > value;
	if ( PerformVariableSubstitutions( valueStart, valueEnd, value ) == false )
	{
		return false;
	}

	// are we concatenating?
	const BFFVariable * varToConcat = nullptr;
	if ( *operatorIter == BFF_VARIABLE_CONCATENATION )
	{
		// find existing
		varToConcat = BFFStackFrame::GetVar( name, frame );
		if ( varToConcat == nullptr )
		{
			Error::Error_1026_VariableNotFoundForConcatenation( operatorIter, name );
			return false;
		}

		// make sure types are compatible
		if ( varToConcat->IsString() )
		{
			// OK - can concat String to String
			AStackString< 1024 > finalValue( varToConcat->GetString() );
			finalValue += value;

			BFFStackFrame::SetVarString( name, finalValue, frame );
			FLOG_INFO( "Appended '%s' to <String> variable '%s' with result '%s'", value.Get(), name.Get(), finalValue.Get() );
			return true;
		}
		else if ( varToConcat->IsArrayOfStrings() )
		{
			// OK - can concat String to ArrayOfStrings
			Array< AString > finalValues( varToConcat->GetArrayOfStrings().GetSize() + 1, false );
			finalValues = varToConcat->GetArrayOfStrings();
			finalValues.Append( value );

			BFFStackFrame::SetVarArrayOfStrings( name, finalValues, frame );
			FLOG_INFO( "Appended '%s' to <ArrayOfStrings> variable '%s' with result of %i items", value.Get(), name.Get(), finalValues.GetSize() );
			return true;
		}
		else
		{
			Error::Error_1027_CannotConcatenate( operatorIter, name, varToConcat->GetType(), BFFVariable::VAR_STRING );
			return false;
		}
	}

	// handle regular assignment of string
	BFFStackFrame::SetVarString( name, value, frame );
	FLOG_INFO( "Registered <string> variable '%s' with value '%s'", name.Get(), value.Get() );
	return true;
}
void RenderPropertyAnimator::onStagingPlayStateChanged() {
    if (mStagingPlayState == RUNNING) {
        (mTarget->mutateStagingProperties().*mPropertyAccess->setter)(finalValue());
    } else if (mStagingPlayState == FINISHED) {
        // We're being canceled, so make sure that whatever values the UI thread
        // is observing for us is pushed over
        mTarget->setPropertyFieldsDirty(dirtyMask());
    }
}
Exemple #3
0
std::string BinaryInputStream::readString (size_t n)
{
    if (n == 0)
    {
        std::string finalValue;
        std::getline(*stream, finalValue, '\0');
        return finalValue;
    }
    else
    {
        char *value = new char[n];
        stream->read(value, n);
        std::string finalValue(value, n);
        delete[] value;
        return finalValue;
    }
}
Exemple #4
0
int main(int argc, char *argv[])
{
    int test = argc > 1 ? atoi(argv[1]) : 0;
    int verbose = argc > 2;

    std::cout << "TEST " << __FILE__ << " CASE " << test << std::endl;

    switch (test) { case 0:
      case 8: {
        // --------------------------------------------------------------------
        // TESTING USAGE EXAMPLE
        // Concerns:
        //   The usage example provided in the component header file must
        //   compile, link, and run on all platforms as shown.
        //
        // Plan:
        //   Run the usage example.
        //
        // Testing:
        //   USAGE EXAMPLE
        // --------------------------------------------------------------------

        if (verbose)
            std::cout << std::endl
                      << "TESTING USAGE EXAMPLE" << std::endl
                      << "=====================" << std::endl;

        Optional<int> value;
        ASSERT(bool(value) == false);
        if (value) { /*... */ }
#if !defined(BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT) \
 || defined(FAIL_USAGE_EXPLICIT)
        bool flag = value;
        ASSERT(flag == false);
#endif

        class FinalClass BSLS_CPP11_FINAL
        {
            int d_value;
        public:
            explicit FinalClass(int value = 0)
                // Initialize the object with the optionally specified 'value'.
                : d_value(value) {}
            int value() const { return d_value; }
                // Returns the object's value.
        };
        class FinalClassDerived
#if !defined(BSLS_COMPILERFEATURES_SUPPORT_FINAL) \
 || defined(FAIL_USAGE_FINAL_CLASS)
            : public FinalClass
#endif
        {
            int d_anotherValue;
        public:
            explicit FinalClassDerived(int value)
                // Initialize the object with the specified 'value'.
                : d_anotherValue(2 * value) {
            }
            int anotherValue() const { return d_anotherValue; }
                // Returns another value for the object.
        };

        FinalClass finalValue(1);
        ASSERT(finalValue.value() == 1);
        FinalClassDerived derivedValue(2);
        ASSERT(derivedValue.anotherValue() == 4);

        struct FinalFunctionBase
        {
            virtual int f() { return 0; }
                // Returns a value associated with the the class's type.
        };
        struct FinalFunctionDerived: FinalFunctionBase
        {
            int f() BSLS_CPP11_FINAL
                // Returns a value associated with the the class's type.
            { return 1; }
        };
        struct FinalFunctionFailure: FinalFunctionDerived
        {
#if !defined(BSLS_COMPILERFEATURES_SUPPORT_FINAL) \
 || defined(FAIL_USAGE_FINAL_FUNCTION)
            int f()
                // Returns a value associated with the the class's type.
            { return 2; }
#endif
        };

        FinalFunctionBase finalFunctionBase;
        ASSERT(finalFunctionBase.f()    == 0);

        FinalFunctionDerived finalFunctionDerived;
        ASSERT(finalFunctionDerived.f() == 1);

        FinalFunctionFailure finalFunctionFailure;
#if defined(BSLS_COMPILERFEATURES_SUPPORT_FINAL)
        ASSERT(finalFunctionFailure.f() == 1);
#else
        ASSERT(finalFunctionFailure.f() == 2);
#endif

        struct OverrideBase
        {
            virtual int f() const
                // Returns a value associated with the type.
            { return 0; }
        };
        struct OverrideSuccess: OverrideBase
        {
            int f() const BSLS_CPP11_OVERRIDE
                // Returns a value associated with the type.
            { return 1; }
        };
        struct OverrideFailure: OverrideBase
        {
            int f()
                // Returns a value associated with the type.
#if !defined(BSLS_COMPILERFEATURES_SUPPORT_OVERRIDE) \
 || defined(FAIL_USAGE_OVERRIDE)
                BSLS_CPP11_OVERRIDE
#endif
            { return 2; }
        };

        OverrideBase overrideBase;
        ASSERT(overrideBase.f() == 0);
        OverrideSuccess overrideSuccess;
        ASSERT(overrideSuccess.f() == 1);
        ASSERT(static_cast<const OverrideBase&>(overrideSuccess).f() == 1);
        OverrideFailure overrideFailure;
        ASSERT(overrideFailure.f() == 2);
        ASSERT(static_cast<const OverrideBase&>(overrideFailure).f() == 0);
      } break;
Exemple #5
0
      humanReadableTime humanReadableTime::convert(t_ullong const _numberOfseconds, 
						   bool const _cont)
      {
         humanReadableTime::HRT_UNIT pri_unit  = humanReadableTime::UNKN;
         t_ullong                    pri_value = 0;

         humanReadableTime::HRT_UNIT sec_unit  = humanReadableTime::UNKN;
         t_ullong                    sec_value = 0;

         t_ullong u_sec, u_min, u_hour, u_day, u_week, u_month, u_year;

         u_sec   = 1ull;
         u_min   = 60ull * u_sec;
         u_hour  = 60ull * u_min;
         u_day   = 24ull * u_hour;
         u_week  = 7ull  * u_day;
         u_month = 4ull  * u_week;
         u_year  = 12ull * u_month;

         // Check for zero.
         if (_numberOfseconds == 0)
            {
               humanReadableTime zerovalue(0, humanReadableTime::SECOND, 
					   0, humanReadableTime::UNKN);
               return zerovalue;
            }

         if (_numberOfseconds >= u_year)
            {
               pri_value = _numberOfseconds / u_year;
               pri_unit  = humanReadableTime::YEAR;

               sec_value = _numberOfseconds - (pri_value * u_year);
               sec_unit  = humanReadableTime::SECOND;
            }
         else if (_numberOfseconds >= u_month)
            {
               pri_value = _numberOfseconds / u_month;
               pri_unit  = humanReadableTime::MONTH;

               sec_value = _numberOfseconds - (pri_value * u_month);
               sec_unit  = humanReadableTime::SECOND;
            }
         else if (_numberOfseconds >= u_week)
            {
               pri_value = _numberOfseconds / u_week;
               pri_unit  = humanReadableTime::WEEK;

               sec_value = _numberOfseconds - (pri_value * u_week);
               sec_unit  = humanReadableTime::SECOND;
            }
         else if (_numberOfseconds >= u_day)
            {
               pri_value = _numberOfseconds / u_day;
               pri_unit  = humanReadableTime::DAY;

               sec_value = _numberOfseconds - (pri_value * u_day);
               sec_unit  = humanReadableTime::SECOND;
            }
         else if (_numberOfseconds >= u_hour)
            {
               pri_value = _numberOfseconds / u_hour;
               pri_unit  = humanReadableTime::HOUR;

               sec_value = _numberOfseconds - (pri_value * u_hour);
               sec_unit  = humanReadableTime::SECOND;
            }

         else if (_numberOfseconds >= u_min)
            {
               pri_value = _numberOfseconds / u_min;
               pri_unit  = humanReadableTime::MINUTE;

               sec_value = _numberOfseconds - (pri_value * u_min);
               sec_unit  = humanReadableTime::SECOND;
            }
         else
            {
               pri_value = _numberOfseconds;
               pri_unit  = humanReadableTime::SECOND;

               sec_value = 0;
               sec_unit  = humanReadableTime::SECOND;
            }

         humanReadableTime finalValue(pri_value, pri_unit, sec_value, sec_unit);

         if (_cont && pri_unit != humanReadableTime::SECOND)
            {
               humanReadableTime hru = humanReadableTime::convert(sec_value, false);
               if (hru.value_unit != humanReadableTime::SECOND)
                  {
                     finalValue.remainder_unit = hru.value_unit;
                     finalValue.remainder      = hru.value;
                  }
            }

         return finalValue;
      }
Exemple #6
0
// StoreVariableString
//------------------------------------------------------------------------------
bool BFFParser::StoreVariableString( const AString & name,
									 const BFFIterator & valueStart, const BFFIterator & valueEnd,
									 const BFFIterator & operatorIter,
									 BFFStackFrame * frame )
{
	// unescape and subsitute embedded variables
	AStackString< 2048 > value;
	if ( PerformVariableSubstitutions( valueStart, valueEnd, value ) == false )
	{
		return false;
	}

	// are we concatenating?
	const BFFVariable * varToConcat = nullptr;
	if ( ( *operatorIter == BFF_VARIABLE_CONCATENATION ) || 
		 ( *operatorIter == BFF_VARIABLE_SUBTRACTION ) )
	{
		// find existing
		varToConcat = BFFStackFrame::GetVar( name, frame );
		if ( varToConcat == nullptr )
		{
			Error::Error_1026_VariableNotFoundForModification( operatorIter, name );
			return false;
		}

		// make sure types are compatible
		if ( varToConcat->IsString() )
		{
			// OK - can concat String to String
			AStackString< 1024 > finalValue( varToConcat->GetString() );
			if ( *operatorIter == BFF_VARIABLE_CONCATENATION )
			{
				finalValue += value;
			}
			else
			{
				finalValue.Replace( value.Get(), "" );
			}

			BFFStackFrame::SetVarString( name, finalValue, frame );
			FLOG_INFO( "%s '%s' %s <String> variable '%s' with result '%s'", 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "Appending" : "Removing",
						value.Get(), 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "to" : "from",
						name.Get(), 
						finalValue.Get() );
			return true;
		}
		else if ( varToConcat->IsArrayOfStrings() )
		{
			// OK - can concat String to ArrayOfStrings
			Array< AString > finalValues( varToConcat->GetArrayOfStrings().GetSize() + 1, false );
			if ( *operatorIter == BFF_VARIABLE_CONCATENATION )
			{
				finalValues = varToConcat->GetArrayOfStrings();
				finalValues.Append( value );
			}
			else
			{
				auto end = varToConcat->GetArrayOfStrings().End();
				for ( auto it=varToConcat->GetArrayOfStrings().Begin(); it!=end; ++it )
				{
					if ( *it != value ) // remove equal strings
					{
						finalValues.Append( *it );
					}
				}
			}

			BFFStackFrame::SetVarArrayOfStrings( name, finalValues, frame );
			FLOG_INFO( "%s '%s' %s <ArrayOfStrings> variable '%s' with result of %i items", 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "Appending" : "Removing",
						value.Get(), 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "to" : "from",
						name.Get(), 
						finalValues.GetSize() );
			return true;
		}
		else
		{
			Error::Error_1027_CannotModify( operatorIter, name, varToConcat->GetType(), BFFVariable::VAR_STRING );
			return false;
		}
	}

	// handle regular assignment of string
	BFFStackFrame::SetVarString( name, value, frame );
	FLOG_INFO( "Registered <string> variable '%s' with value '%s'", name.Get(), value.Get() );
	return true;
}
Exemple #7
0
      humanReadableUnit humanReadableUnit::convert(t_ullong const _numberOfbytes, bool const _cont)
      {
         humanReadableUnit::EIC_UNIT pri_unit  = humanReadableUnit::UNKN;
         t_ullong                    pri_value = 0;

         humanReadableUnit::EIC_UNIT sec_unit  = humanReadableUnit::UNKN;
         t_ullong                    sec_value = 0;

         t_ullong u_kib, u_mib, u_gib, u_tib, u_pib;

         u_kib = (1024ull);
         u_mib = (1024ull * u_kib);
         u_gib = (1024ull * u_mib);
         u_tib = (1024ull * u_gib);
         u_pib = (1024ull * u_tib);
         //u_eib = (1024 * u_pib);

         // Check for zero.
         if (_numberOfbytes == 0)
            {
               humanReadableUnit zerovalue(0, humanReadableUnit::B, 0, humanReadableUnit::UNKN);
               return zerovalue;
            }

         if (_numberOfbytes >= u_pib)
            {
               pri_value = _numberOfbytes / u_pib;
               pri_unit  = humanReadableUnit::PiB;

               sec_value = _numberOfbytes - (pri_value * u_pib);
               sec_unit  = humanReadableUnit::B;
            }
         else if (_numberOfbytes >= u_tib)
            {
               pri_value = _numberOfbytes / u_tib;
               pri_unit  = humanReadableUnit::TiB;

               sec_value = _numberOfbytes - (pri_value * u_tib);
               sec_unit  = humanReadableUnit::B;
            }
         else if (_numberOfbytes >= u_gib)
            {
               pri_value = _numberOfbytes / u_gib;
               pri_unit  = humanReadableUnit::GiB;

               sec_value = _numberOfbytes - (pri_value * u_gib);
               sec_unit  = humanReadableUnit::B;
            }
         else if (_numberOfbytes >= u_mib)
            {
               pri_value = _numberOfbytes / u_mib;
               pri_unit  = humanReadableUnit::MiB;

               sec_value = _numberOfbytes - (pri_value * u_mib);
               sec_unit  = humanReadableUnit::B;
            }
         else if (_numberOfbytes >= u_kib)
            {
               pri_value = _numberOfbytes / u_kib;
               pri_unit  = humanReadableUnit::KiB;

               sec_value = _numberOfbytes - (pri_value * u_kib);
               sec_unit  = humanReadableUnit::B;
            }
         else
            {
               pri_value = _numberOfbytes;
               pri_unit  = humanReadableUnit::B;

               sec_value = 0;
               sec_unit  = humanReadableUnit::B;
            }

         humanReadableUnit finalValue(pri_value, pri_unit, sec_value, sec_unit);

         if (_cont == true && pri_unit != humanReadableUnit::B)
            {
               humanReadableUnit hru = humanReadableUnit::convert(sec_value, false);
               if (hru.value_unit != humanReadableUnit::B)
                  {
                     finalValue.remainder_unit = hru.value_unit;
                     finalValue.remainder      = hru.value;
                  }
            }

         return finalValue;
      }