Exemple #1
0
void
hashMapInsert(Thread* t, object map, object key, object value,
              uint32_t (*hash)(Thread*, object))
{
  // note that we reinitialize the array variable whenever an
  // allocation (and thus possibly a collection) occurs, in case the
  // array changes due to a table resize.

  PROTECT(t, map);

  uint32_t h = hash(t, key);

  bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType);

  object array = hashMapArray(t, map);

  ++ hashMapSize(t, map);

  if (array == 0 or hashMapSize(t, map) >= arrayLength(t, array) * 2) { 
    PROTECT(t, key);
    PROTECT(t, value);

    hashMapResize(t, map, hash, array ? arrayLength(t, array) * 2 : 16);

    array = hashMapArray(t, map);
  }

  object k = key;

  if (weak) {
    PROTECT(t, key);
    PROTECT(t, value);

    object r = makeWeakReference(t, 0, 0, 0, 0);
    jreferenceTarget(t, r) = key;
    jreferenceVmNext(t, r) = t->m->weakReferences;
    t->m->weakReferences = r;
    k = r;

    array = hashMapArray(t, map);
  }

  object n = makeTriple(t, k, value, 0);

  array = hashMapArray(t, map);

  unsigned index = h & (arrayLength(t, array) - 1);

  set(t, n, TripleThird, arrayBody(t, array, index));
  set(t, array, ArrayBody + (index * BytesPerWord), n);

  if (hashMapSize(t, map) <= arrayLength(t, array) / 3) {
    // this might happen if nodes were removed during GC in which case
    // we weren't able to resize at the time
    hashMapResize(t, map, hash, arrayLength(t, array) / 2);
  }
}
Exemple #2
0
    Result<Function<T>> operator()(const V& value) const {
        if (!isObject(value)) {
            return Error { "function must be an object" };
        }

        auto stopsValue = objectMember(value, "stops");
        if (!stopsValue) {
            return Error { "function value must specify stops" };
        }

        if (!isArray(*stopsValue)) {
            return Error { "function stops must be an array" };
        }

        if (arrayLength(*stopsValue) == 0) {
            return Error { "function must have at least one stop" };
        }

        std::vector<std::pair<float, T>> stops;
        for (std::size_t i = 0; i < arrayLength(*stopsValue); ++i) {
            const auto& stopValue = arrayMember(*stopsValue, i);

            if (!isArray(stopValue)) {
                return Error { "function stop must be an array" };
            }

            if (arrayLength(stopValue) != 2) {
                return Error { "function stop must have two elements" };
            }

            optional<float> z = toNumber(arrayMember(stopValue, 0));
            if (!z) {
                return Error { "function stop zoom level must be a number" };
            }

            Result<T> v = convert<T>(arrayMember(stopValue, 1));
            if (!v) {
                return v.error();
            }

            stops.emplace_back(*z, *v);
        }

        auto baseValue = objectMember(value, "base");
        if (!baseValue) {
            return Function<T>(stops, 1.0f);
        }

        optional<float> base = toNumber(*baseValue);
        if (!base) {
            return Error { "function base must be a number"};
        }

        return Function<T>(stops, *base);
    }
Exemple #3
0
void
hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object),
              unsigned size)
{
  PROTECT(t, map);

  object newArray = 0;

  if (size) {
    object oldArray = hashMapArray(t, map);
    PROTECT(t, oldArray);

    unsigned newLength = nextPowerOfTwo(size);
    if (oldArray and arrayLength(t, oldArray) == newLength) {
      return;
    }

    newArray = makeArray(t, newLength);

    if (oldArray != hashMapArray(t, map)) {
      // a resize was performed during a GC via the makeArray call
      // above; nothing left to do
      return;
    }

    if (oldArray) {
      bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType);
      for (unsigned i = 0; i < arrayLength(t, oldArray); ++i) {
        object next;
        for (object p = arrayBody(t, oldArray, i); p; p = next) {
          next = tripleThird(t, p);

          object k = tripleFirst(t, p);
          if (weak) {
            k = jreferenceTarget(t, k);
            if (k == 0) {
              continue;
            }
          }

          unsigned index = hash(t, k) & (newLength - 1);

          set(t, p, TripleThird, arrayBody(t, newArray, index));
          set(t, newArray, ArrayBody + (index * BytesPerWord), p);
        }
      }
    }
  }
  
  set(t, map, HashMapArray, newArray);
}
Exemple #4
0
object
growArray(Thread* t, object array)
{
  PROTECT(t, array);

  object newArray = makeArray
    (t, array == 0 ? 16 : (arrayLength(t, array) * 2));

  if (array) {
    memcpy(&arrayBody(t, newArray, 0), &arrayBody(t, array, 0),
           arrayLength(t, array));
  }

  return newArray;
}
Exemple #5
0
std::string strPrintF(const char * format, ...)
{
// Suppress "format string is not a string literal" on GCC and Clang.
#ifdef __GNUC__
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif // __GNUC__

    va_list vaArgs;
    char buffer[2048];
    constexpr int available = arrayLength(buffer);

    va_start(vaArgs, format);
    int result = std::vsnprintf(buffer, available, format, vaArgs);
    va_end(vaArgs);

    if (result < 0)
    {
        result = 0;
    }
    else if (result >= available)
    {
        result = available - 1;
    }

    buffer[result] = '\0';
    return buffer;

#ifdef __GNUC__
    #pragma GCC diagnostic pop
#endif // __GNUC__
}
Exemple #6
0
void NValue::castAndSortAndDedupArrayForInList(const ValueType outputType, std::vector<NValue> &outList) const
{
    int size = arrayLength();

    // make a set to eliminate unique values in O(nlogn) time
    std::set<StlFriendlyNValue> uniques;

    // iterate over the array of values and build a sorted set of unique
    // values that don't overflow or violate unique constaints
    // (n.b. sorted set means dups are removed)
    for (int i = 0; i < size; i++) {
        NValue value = itemAtIndex(i);
        // cast the value to the right type and catch overflow/cast problems
        try {
            StlFriendlyNValue stlValue;
            stlValue = value.castAs(outputType);
            std::pair<std::set<StlFriendlyNValue>::iterator, bool> ret;
            ret = uniques.insert(stlValue);
        }
        // cast exceptions mean the in-list test is redundant
        // don't include these values in the materialized table
        // TODO: make this less hacky
        catch (SQLException &sqlException) {}
    }

    // insert all items in the set in order
    std::set<StlFriendlyNValue>::const_iterator iter;
    for (iter = uniques.begin(); iter != uniques.end(); iter++) {
        outList.push_back(*iter);
    }
}
Exemple #7
0
object
hashMapFindNode(Thread* t, object map, object key,
                uint32_t (*hash)(Thread*, object),
                bool (*equal)(Thread*, object, object))
{
  bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType);

  object array = hashMapArray(t, map);
  if (array) {
    unsigned index = hash(t, key) & (arrayLength(t, array) - 1);
    for (object n = arrayBody(t, array, index); n; n = tripleThird(t, n)) {
      object k = tripleFirst(t, n);
      if (weak) {
        k = jreferenceTarget(t, k);
        if (k == 0) {
          continue;
        }
      }

      if (equal(t, key, k)) {
        return n;
      }
    }
  }
  return 0;
}
optional<std::map<D, R>> convertStops(const V& value, Error& error) {
    auto stopsValue = objectMember(value, "stops");
    if (!stopsValue) {
        error = { "function value must specify stops" };
        return {};
    }

    if (!isArray(*stopsValue)) {
        error = { "function stops must be an array" };
        return {};
    }

    if (arrayLength(*stopsValue) == 0) {
        error = { "function must have at least one stop" };
        return {};
    }

    std::map<D, R> stops;
    for (std::size_t i = 0; i < arrayLength(*stopsValue); ++i) {
        const auto& stopValue = arrayMember(*stopsValue, i);

        if (!isArray(stopValue)) {
            error = { "function stop must be an array" };
            return {};
        }

        if (arrayLength(stopValue) != 2) {
            error = { "function stop must have two elements" };
            return {};
        }

        optional<D> d = convert<D>(arrayMember(stopValue, 0), error);
        if (!d) {
            return {};
        }

        optional<R> r = convert<R>(arrayMember(stopValue, 1), error);
        if (!r) {
            return {};
        }

        stops.emplace(*d, *r);
    }

    return stops;
}
    Result<Tileset> operator()(const V& value) const {
        Tileset result;

        auto tiles = objectMember(value, "tiles");
        if (!tiles) {
            return Error { "source must have tiles" };
        }

        if (!isArray(*tiles)) {
            return Error { "source tiles must be an array" };
        }

        for (std::size_t i = 0; i < arrayLength(*tiles); i++) {
            optional<std::string> urlTemplate = toString(arrayMember(*tiles, i));
            if (!urlTemplate) {
                return Error { "source tiles member must be a string" };
            }
            result.tiles.push_back(std::move(*urlTemplate));
        }

        auto schemeValue = objectMember(value, "scheme");
        if (schemeValue) {
            optional<std::string> scheme = toString(*schemeValue);
            if (scheme && *scheme == "tms") {
                result.scheme = Tileset::Scheme::TMS;
            }
        }

        auto minzoomValue = objectMember(value, "minzoom");
        if (minzoomValue) {
            optional<float> minzoom = toNumber(*minzoomValue);
            if (!minzoom || *minzoom < 0 || *minzoom > std::numeric_limits<uint8_t>::max()) {
                return Error { "invalid minzoom" };
            }
            result.zoomRange.min = *minzoom;
        }

        auto maxzoomValue = objectMember(value, "maxzoom");
        if (maxzoomValue) {
            optional<float> maxzoom = toNumber(*maxzoomValue);
            if (!maxzoom || *maxzoom < 0 || *maxzoom > std::numeric_limits<uint8_t>::max()) {
                return Error { "invalid maxzoom" };
            }
            result.zoomRange.max = *maxzoom;
        }

        auto attributionValue = objectMember(value, "attribution");
        if (attributionValue) {
            optional<std::string> attribution = toString(*attributionValue);
            if (!attribution) {
                return Error { "source attribution must be a string" };
            }
            result.attribution = std::move(*attribution);
        }

        return result;
    }
Exemple #10
0
    optional<Filter> operator()(const V& value, Error& error) const {
        if (!isArray(value)) {
            error = { "filter expression must be an array" };
            return {};
        }

        if (arrayLength(value) < 1) {
            error = { "filter expression must have at least 1 element" };
            return {};
        }

        optional<std::string> op = toString(arrayMember(value, 0));
        if (!op) {
            error = { "filter operator must be a string" };
            return {};
        }

        if (*op == "==") {
            return convertEqualityFilter<EqualsFilter, TypeEqualsFilter, IdentifierEqualsFilter>(value, error);
        } else if (*op == "!=") {
            return convertEqualityFilter<NotEqualsFilter, TypeNotEqualsFilter, IdentifierNotEqualsFilter>(value, error);
        } else if (*op == ">") {
            return convertBinaryFilter<GreaterThanFilter>(value, error);
        } else if (*op == ">=") {
            return convertBinaryFilter<GreaterThanEqualsFilter>(value, error);
        } else if (*op == "<") {
            return convertBinaryFilter<LessThanFilter>(value, error);
        } else if (*op == "<=") {
            return convertBinaryFilter<LessThanEqualsFilter>(value, error);
        } else if (*op == "in") {
            return convertSetFilter<InFilter, TypeInFilter, IdentifierInFilter>(value, error);
        } else if (*op == "!in") {
            return convertSetFilter<NotInFilter, TypeNotInFilter, IdentifierNotInFilter>(value, error);
        } else if (*op == "all") {
            return convertCompoundFilter<AllFilter>(value, error);
        } else if (*op == "any") {
            return convertCompoundFilter<AnyFilter>(value, error);
        } else if (*op == "none") {
            return convertCompoundFilter<NoneFilter>(value, error);
        } else if (*op == "has") {
            return convertUnaryFilter<HasFilter, HasIdentifierFilter>(value, error);
        } else if (*op == "!has") {
           return convertUnaryFilter<NotHasFilter, NotHasIdentifierFilter>(value, error);
        }

        error = { R"(filter operator must be one of "==", "!=", ">", ">=", "<", "<=", "in", "!in", "all", "any", "none", "has", or "!has")" };
        return {};
    }

private:
    optional<Value> normalizeValue(const optional<Value>& value, Error& error) const {
        if (!value) {
            error = { "filter expression value must be a boolean, number, or string" };
            return {};
        } else {
            return *value;
void mergeSort(int A[],int n){
if(n<2)
 return;
int i,j,mid;
n=arrayLength(A);

mid=n/2;
int ln=mid;
int rn=n-(mid+1);
int L[ln],R[rn];
int nL=arrayLength(L);
int nR=arrayLength(R);
for(i = 0;i<mid;i++)
 L[i] = A[i]; // creating left subarray
for(i = mid;i<n;i++)
 R[i-mid] = A[i]; // creating right subarray
mergeSort(L,mid);  // sorting the left subarray
mergeSort(R,n-mid);  // sorting the right subarray
merge(L,ln,R,rn,A);  // Merging
}
Exemple #12
0
void a3dsFree(a3dsDataT* a3ds) {
    for (int i = 0; i < arrayLength(a3ds->materials); i++) {
        a3dsMaterialDataT* mat = *(a3dsMaterialDataT**)arrayGet(a3ds->materials, i);
        free(mat);
    }

    arrayFree(a3ds->materials);

    for (int i = 0; i < arrayLength(a3ds->objects); i++) {
        a3dsObjectDataT* obj = *(a3dsObjectDataT**)arrayGet(a3ds->objects, i);

        if (obj->mesh)
            free(obj->mesh);

        free(obj);
    }

    arrayFree(a3ds->objects);
    free(a3ds);
}
Exemple #13
0
int indexOf(char array[], char c) {
	int i;
	for(i = 0; i < arrayLength(array); i++) {
		if(array[i] == c) {
			return i;
		} else {
			continue;
		}
	}
	return -1; // not in the array
}
Exemple #14
0
const string* a3dsGetObjectMaterialName(const a3dsDataT* a3ds,
                                        const string* object_name)
{
    for (int i = 0; i < arrayLength(a3ds->objects); i++) {
        a3dsObjectDataT** o = arrayGet(a3ds->objects, i);
        if ((*o)->mesh && strcmp(object_name, (*o)->name) == 0)
            return ((*o)->mesh->material);
    }

    return (NULL);
}
Exemple #15
0
object
hashMapRemove(Thread* t, object map, object key,
              uint32_t (*hash)(Thread*, object),
              bool (*equal)(Thread*, object, object))
{
  bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType);

  object array = hashMapArray(t, map);
  object o = 0;
  if (array) {
    unsigned index = hash(t, key) & (arrayLength(t, array) - 1);
    object p = 0;
    for (object n = arrayBody(t, array, index); n;) {
      object k = tripleFirst(t, n);
      if (weak) {
        k = jreferenceTarget(t, k);
        if (k == 0) {
          n = tripleThird(t, hashMapRemoveNode(t, map, index, p, n));
          continue;
        }
      }

      if (equal(t, key, k)) {
        o = tripleSecond(t, hashMapRemoveNode(t, map, index, p, n));
        break;
      } else {
        p = n;
        n = tripleThird(t, n);
      }
    }

    if ((not t->m->collecting)
        and hashMapSize(t, map) <= arrayLength(t, array) / 3)
    {
      PROTECT(t, o);
      hashMapResize(t, map, hash, arrayLength(t, array) / 2);
    }
  }

  return o;
}
Exemple #16
0
void externFunction() {

	CurrentAddress();
	int *p = array;	//	指针与数组的不同 P86
	int count = arrayLength();
	for (int i = 0; i < count; ++i)
	{
		array[i] = i;
		printf("%d  ", p[i]);
	}
	printf("\n");
}
Exemple #17
0
const a3dsMaterialDataT* a3dsGetMaterialData(const a3dsDataT* a3ds,
                                             const string* material_name)
{
    if (!material_name)
        return (NULL);

    for (int i = 0; i < arrayLength(a3ds->materials); i++) {
        a3dsMaterialDataT** m = arrayGet(a3ds->materials, i);
        if (strcmp(material_name, (*m)->name) == 0)
            return (*m);
    }

    return (NULL);
}
Exemple #18
0
const a3dsObjectDataT* a3dsGetObjectData(const a3dsDataT* a3ds,
                                         const string* object_name)
{
    if (!object_name)
        return (NULL);

    for (int i = 0; i < arrayLength(a3ds->objects); i++) {
        a3dsObjectDataT** o = arrayGet(a3ds->objects, i);
        if (strcmp(object_name, (*o)->name) == 0)
            return (*o);
    }

    return (NULL);
}
    optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const {
        if (!isArray(value) || arrayLength(value) != N) {
            error = { "value must be an array of " + util::toString(N) + " numbers" };
            return {};
        }

        std::array<float, N> result;
        for (size_t i = 0; i < N; i++) {
            optional<float> n = toNumber(arrayMember(value, i));
            if (!n) {
                error = { "value must be an array of " + util::toString(N) + " numbers" };
                return {};
            }
            result[i] = *n;
        }
        return result;
    }
// -----------------------------------------------------------------------------
// CPsmSession::ReadConfigArrayL
// -----------------------------------------------------------------------------
//
void CPsmSession::ReadConfigArrayL( RConfigInfoArray& aArray, const RMessage2& aMessage )
    {
    COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ReadConfigArrayL()" ) ) );

    const TInt configCount( aMessage.Int1() );
    TInt arrayLength( configCount * sizeof( TPsmsrvConfigInfo ) );

    aArray.ReserveL(configCount);    
    //Fill the array with dummy items
    for(TInt x = 0; x < configCount; ++x )
    	{
        // Append empty config infos to array
    	aArray.AppendL( TPsmsrvConfigInfo() );
    	}

    TPtr8 arrayPtr( ( TUint8* )&aArray[0], arrayLength, arrayLength );
    aMessage.ReadL( 0, arrayPtr, 0 );

    COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ReadConfigArrayL - return" ) ) );
    }
static WKEventModifiers parseModifierArray(JSContextRef context, JSValueRef arrayValue)
{
    if (!arrayValue)
        return 0;
    if (!JSValueIsObject(context, arrayValue))
        return 0;
    JSObjectRef array = const_cast<JSObjectRef>(arrayValue);
    unsigned length = arrayLength(context, array);
    WKEventModifiers modifiers = 0;
    for (unsigned i = 0; i < length; i++) {
        JSValueRef exception = 0;
        JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception);
        if (exception)
            continue;
        JSRetainPtr<JSStringRef> string(Adopt, JSValueToStringCopy(context, value, &exception));
        if (exception)
            continue;
        modifiers |= parseModifier(string.get());
    }
    return modifiers;
}
Exemple #22
0
static optional<std::unique_ptr<Source>> convertImageSource(const std::string& id,
                                                            const Convertible& value,
                                                            Error& error) {
    auto urlValue = objectMember(value, "url");
    if (!urlValue) {
        error = { "Image source must have a url value" };
        return {};
    }
    
    auto urlString = toString(*urlValue);
    if (!urlString) {
        error = { "Image url must be a URL string" };
        return {};
    }
    
    auto coordinatesValue = objectMember(value, "coordinates");
    if (!coordinatesValue) {
        error = { "Image source must have a coordinates values" };
        return {};
    }
    
    if (!isArray(*coordinatesValue) || arrayLength(*coordinatesValue) != 4) {
        error = { "Image coordinates must be an array of four longitude latitude pairs" };
        return {};
    }
    
    std::array<LatLng, 4> coordinates;
    for (std::size_t i=0; i < 4; i++) {
        auto latLng = conversion::convert<LatLng>(arrayMember(*coordinatesValue,i), error);
        if (!latLng) {
            return {};
        }
        coordinates[i] = *latLng;
    }
    auto result = std::make_unique<ImageSource>(id, coordinates);
    result->setURL(*urlString);

    return { std::move(result) };
}
Exemple #23
0
static const Ndbcntr::SysColumn
column_SYSTAB_0[] = {
  { 0, "SYSKEY_0",
    DictTabInfo::ExtUnsigned, 1,
    true, false
  },
  { 1, "NEXTID",
    DictTabInfo::ExtBigunsigned, 1,
    false, false
  }
};

const Ndbcntr::SysTable
Ndbcntr::g_sysTable_SYSTAB_0 = {
  "sys/def/SYSTAB_0",
  arrayLength(column_SYSTAB_0), column_SYSTAB_0,
  DictTabInfo::SystemTable,
  DictTabInfo::AllNodesSmallTable,
  true, ~0
};

// NDB$EVENTS_0

static const Ndbcntr::SysColumn
column_NDBEVENTS_0[] = {
  { 0, "NAME",
    DictTabInfo::ExtBinary, MAX_TAB_NAME_SIZE,
    true, false
  },
  { 1, "EVENT_TYPE",
    DictTabInfo::ExtUnsigned, 1,
optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) {
    auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error, convertTokens);
    if (!expression) {
        return nullopt;
    }

    optional<T> defaultValue{};

    auto defaultValueValue = objectMember(value, "default");
    if (defaultValueValue) {
        defaultValue = convert<T>(*defaultValueValue, error);
        if (!defaultValue) {
            error.message = R"(wrong type for "default": )" + error.message;
            return nullopt;
        }
    }

    return PropertyExpression<T>(std::move(*expression), defaultValue);
}

template optional<PropertyExpression<AlignmentType>>
    convertFunctionToExpression<AlignmentType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<bool>>
    convertFunctionToExpression<bool>(const Convertible&, Error&, bool);
template optional<PropertyExpression<CirclePitchScaleType>>
    convertFunctionToExpression<CirclePitchScaleType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<float>>
    convertFunctionToExpression<float>(const Convertible&, Error&, bool);
template optional<PropertyExpression<HillshadeIlluminationAnchorType>>
    convertFunctionToExpression<HillshadeIlluminationAnchorType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<IconTextFitType>>
    convertFunctionToExpression<IconTextFitType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<LightAnchorType>>
    convertFunctionToExpression<LightAnchorType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<LineCapType>>
    convertFunctionToExpression<LineCapType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<LineJoinType>>
    convertFunctionToExpression<LineJoinType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<Color>>
    convertFunctionToExpression<Color>(const Convertible&, Error&, bool);
template optional<PropertyExpression<Position>>
    convertFunctionToExpression<Position>(const Convertible&, Error&, bool);
template optional<PropertyExpression<RasterResamplingType>>
    convertFunctionToExpression<RasterResamplingType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<std::array<float, 2>>>
    convertFunctionToExpression<std::array<float, 2>>(const Convertible&, Error&, bool);
template optional<PropertyExpression<std::array<float, 4>>>
    convertFunctionToExpression<std::array<float, 4>>(const Convertible&, Error&, bool);
template optional<PropertyExpression<std::string>>
    convertFunctionToExpression<std::string>(const Convertible&, Error&, bool);
template optional<PropertyExpression<std::vector<float>>>
    convertFunctionToExpression<std::vector<float>>(const Convertible&, Error&, bool);
template optional<PropertyExpression<std::vector<std::string>>>
    convertFunctionToExpression<std::vector<std::string>>(const Convertible&, Error&, bool);
template optional<PropertyExpression<SymbolAnchorType>>
    convertFunctionToExpression<SymbolAnchorType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<SymbolPlacementType>>
    convertFunctionToExpression<SymbolPlacementType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<SymbolZOrderType>>
    convertFunctionToExpression<SymbolZOrderType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<TextJustifyType>>
    convertFunctionToExpression<TextJustifyType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<TextTransformType>>
    convertFunctionToExpression<TextTransformType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<TranslateAnchorType>>
    convertFunctionToExpression<TranslateAnchorType>(const Convertible&, Error&, bool);
    
template optional<PropertyExpression<Formatted>>
    convertFunctionToExpression<Formatted>(const Convertible&, Error&, bool);

// Ad-hoc Converters for double and int64_t. We should replace float with double wholesale,
// and promote the int64_t Converter to general use (and it should check that the input is
// an integer).
template <>
struct Converter<double> {
    optional<double> operator()(const Convertible& value, Error& error) const {
        auto converted = convert<float>(value, error);
        if (!converted) {
            return nullopt;
        }
        return *converted;
    }
};

template <>
struct Converter<int64_t> {
    optional<int64_t> operator()(const Convertible& value, Error& error) const {
        auto converted = convert<float>(value, error);
        if (!converted) {
            return nullopt;
        }
        return *converted;
    }
};

enum class FunctionType {
    Interval,
    Exponential,
    Categorical,
    Identity,
    Invalid
};

static bool interpolatable(type::Type type) {
    return type.match(
        [&] (const type::NumberType&) {
            return true;
        },
        [&] (const type::ColorType&) {
            return true;
        },
        [&] (const type::Array& array) {
            return array.N && array.itemType == type::Number;
        },
        [&] (const auto&) {
            return false;
        }
    );
}

static optional<std::unique_ptr<Expression>> convertLiteral(type::Type type, const Convertible& value, Error& error, bool convertTokens = false) {
    return type.match(
        [&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> {
            auto result = convert<float>(value, error);
            if (!result) {
                return nullopt;
            }
            return literal(double(*result));
        },
        [&] (const type::BooleanType&) -> optional<std::unique_ptr<Expression>> {
            auto result = convert<bool>(value, error);
            if (!result) {
                return nullopt;
            }
            return literal(*result);
        },
        [&] (const type::StringType&) -> optional<std::unique_ptr<Expression>> {
            auto result = convert<std::string>(value, error);
            if (!result) {
                return nullopt;
            }
            return convertTokens ? convertTokenStringToExpression(*result) : literal(*result);
        },
        [&] (const type::ColorType&) -> optional<std::unique_ptr<Expression>> {
            auto result = convert<Color>(value, error);
            if (!result) {
                return nullopt;
            }
            return literal(*result);
        },
        [&] (const type::Array& array) -> optional<std::unique_ptr<Expression>> {
            if (!isArray(value)) {
                error.message = "value must be an array";
                return nullopt;
            }
            if (array.N && arrayLength(value) != *array.N) {
                error.message = "value must be an array of length " + util::toString(*array.N);
                return nullopt;
            }
            return array.itemType.match(
                [&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> {
                    std::vector<expression::Value> result;
                    result.reserve(arrayLength(value));
                    for (std::size_t i = 0; i < arrayLength(value); ++i) {
                        optional<float> number = toNumber(arrayMember(value, i));
                        if (!number) {
                            error.message = "value must be an array of numbers";
                            return nullopt;
                        }
                        result.push_back(double(*number));
                    }
                    return literal(result);
                },
                [&] (const type::StringType&) -> optional<std::unique_ptr<Expression>> {
                    std::vector<expression::Value> result;
                    result.reserve(arrayLength(value));
                    for (std::size_t i = 0; i < arrayLength(value); ++i) {
                        optional<std::string> string = toString(arrayMember(value, i));
                        if (!string) {
                            error.message = "value must be an array of strings";
                            return nullopt;
                        }
                        result.push_back(*string);
                    }
                    return literal(result);
                },
                [&] (const auto&) -> optional<std::unique_ptr<Expression>> {
                    assert(false); // No properties use this type.
                    return nullopt;
                }
            );
        },
Exemple #25
0
//max name size = 15
//will modify block_map
Inode* writeInode(disk_t disk, int block, int * gpointers,bool directory, char * nametemp){
	int * blkmap = read_block_map(disk);
	blkmap[block] = 1;
	write_block_map(disk,blkmap);
	
	int size = arrayLength(gpointers);
	int maxsize = (disk->block_size-20-(ceil(log10(disk->size))*2)/(ceil(log10(disk->size))+1));
	int * pointers = malloc(sizeof(int) * (size+1));
	int i,j;
	int strlength = length(nametemp);
	char * name = malloc(sizeof(char)*  16);
	for(i = 0; i < 15 && nametemp[i] != '\0';i+=1){
		name[i] = nametemp[i];
	}
	name[i] = '\0';
	int * wpointers = malloc(sizeof(int) * (size + 1));
	for(i = 0; i < size; i+=1){
		pointers[i] = gpointers[i];
		wpointers[i] = gpointers[i];
	}
	wpointers[i] = '\0';
	pointers[i] = '\0';
	char * potSize;
	if(size > (maxsize)){ //-4 for 3 \n and 1 \0 - 16 for name length
		int * newpointers = malloc(sizeof(int) * (maxsize+1));
		int * extrapointers = malloc(sizeof(int) * (size-maxsize+1));
		for(i = 0; i < maxsize;i+=1){
			newpointers[i] = pointers[i];
		}
		newpointers[i] = '\0';
		free(wpointers);
		wpointers = newpointers;
		for(j = 0; j <size-maxsize;j+=1){
			extrapointers[j] = pointers[i];
			i+=1;
		}
		
		extrapointers[j] = '\0';
		int newblk;
		
		for(i = 0; i < disk->size;i+=1){
			if(blkmap[i] == 0){
				newblk = i;
				break;
			}
		}
		freeInode(writeInode(disk,newblk,extrapointers,directory,name));
	}
	unsigned char *strings[6];
	potSize = int2str(size);
	strings[0] = (directory)? "0" : potSize;

	char * list = intArray2charArray(wpointers);
	char * pntrs = malloc(sizeof(char) * (length(list)+2));
	pntrs[0] = '\n';

	pntrs[1] = '\0';
	strcat(pntrs,list);
	strings[1] = pntrs;
	strings[2] = "\n";
	strings[3] = name;
	strings[4] = "\n";
	strings[5] = NULL;
	
	unsigned char *databuf = calloc(disk->block_size, sizeof(unsigned char) );
	copy2buf(databuf,strings,0);
	writeblock(disk,block,databuf);
	free(list);
	free(pntrs);
	free(databuf);
	//free(name);
	free(blkmap);
	free(potSize);
	free(wpointers);
	return createInode(size,pointers,directory,block,name);
}
Exemple #26
0
void printArray(const StringArray* array)
{
  for (size_t i = 0; i < arrayLength(array); i++)
    printf("%s\n", getElementInArray(array, i));
}
Exemple #27
0
	{
		createSimpleButton(vect(0,192-(i+1)*16,0), mp[i].string, mp[i].targetFunction);
	}
}

extern u8 logoAlpha;

void startMenuPlayButtonFunction(sguiButton_struct* b)
{
	testTransition=startCameraTransition(&cameraStates[4],&cameraStates[0],48);
	setupMenuPage(mainMenuPage, mainMenuPageLength);
	logoAlpha=0;
}

menuButton_struct startMenuPage[]={(menuButton_struct){"START", (buttonTargetFunction)startMenuPlayButtonFunction}};
u8 startMenuPageLength=arrayLength(startMenuPage);

void mainMenuPlayButtonFunction(sguiButton_struct* b)
{
	testTransition=startCameraTransition(&cameraStates[0],&cameraStates[1],48);
	setupMenuPage(playMenuPage, playMenuPageLength);
}

void mainMenuCreateButtonFunction(sguiButton_struct* b)
{
	testTransition=startCameraTransition(&cameraStates[0],&cameraStates[2],64);
	setupMenuPage(createMenuPage, createMenuPageLength);
}

menuButton_struct mainMenuPage[]={(menuButton_struct){"Options", NULL}, (menuButton_struct){"Create", (buttonTargetFunction)mainMenuCreateButtonFunction}, (menuButton_struct){"Play", (buttonTargetFunction)mainMenuPlayButtonFunction}};
u8 mainMenuPageLength=arrayLength(mainMenuPage);