Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

range plugin #1334

Merged
merged 17 commits into from
Mar 5, 2017
Merged

range plugin #1334

merged 17 commits into from
Mar 5, 2017

Conversation

tom-wa
Copy link
Contributor

@tom-wa tom-wa commented Feb 9, 2017

Purpose

range plugin preview

Checklist

  • commit messages are fine (with references to issues)
  • I ran all tests and everything went fine
  • I added unit tests
  • affected documentation is fixed
  • I added code comments, logging, and assertions
  • meta data is updated (e.g. README.md of plugins)

Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some refactoring would be good and the usual things are missing (docu, comments). But looks nice for a first draft!

{
pos = 1;
char * endPtr;
a = strtoll (ptr, &endPtr, 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move this code to a base lib? It is so common..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think there's much gain in it, but probably the way the current version handles it (union + enum) ?


init (argc, argv);

test ("5", 1, "1-10");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice test code!

@tom-wa tom-wa changed the title range: initial commit range plugin Feb 9, 2017
Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments.

## Dependencies ##

None.

## Examples ##

None.
```sh
# Backup-and-Restore:/examples/range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to add the test in tests/shell/shell_recorder/tutorial_wrapper/CMakeLists.txt or, (even better) let us automatically include all plugins README.md to be checked with the shell recorder!

You can use `scripts/copy-range`
to automatically rename everything to your
plugin name:
The plugin checks every Key in the Keyset for the Metakey `check/range` which contains either a single range with the syntax `[-]min-[-]max`, or a list of ranges separated by `,` and tests if the Key value is within the range(s).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are spaces allowed? Please do not make lines too long.

@tom-wa tom-wa force-pushed the range branch 2 times, most recently from 7084487 to 71fabb9 Compare February 28, 2017 06:38
@tom-wa tom-wa mentioned this pull request Feb 28, 2017
6 tasks
Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, nicely done! Please rebase and refactor a bit.

doc/METADATA.ini Outdated
[check/range/type]
status= implemented
usedby/plugin= range
description= type of range (INT, FLOAT, HEX or CHAR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use check/type and type instead?

@@ -1033,3 +1033,17 @@ severity:error
ingroup:plugin
module:date
macro:D_T_FMT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs rebase

@@ -202,6 +202,7 @@ copied by another plugin just before):
- [conditionals](conditionals/) by using if-then-else like statements
- [required](required/) rejects non-required keys
- [date](date/) validates date and time data
- [range](range/) checks if a value is within a specific range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specific -> given


## Usage ##

The plugin checks every Key in the Keyset for the Metakey `check/range` which contains either a single range with the syntax `[-]min-[-]max`, or a list of ranges separated by `,` and tests if the Key value is within the range(s).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it also possible to specify 3,5,7?


The plugin checks every Key in the Keyset for the Metakey `check/range` which contains either a single range with the syntax `[-]min-[-]max`, or a list of ranges separated by `,` and tests if the Key value is within the range(s).

`check/range/type` can be used to specify the datatype. If not specified otherwise the default value is `INT`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use type/check/type here, otherwise this is a unnecessary pitfall.

(For hex we need an extra meta data, see discussion #1388)

Internally, you can use INT,.. but please not in the user interface.


# should succeed
kdb set /examples/range/value 5
kdb setmeta user/examples/range/value check/range "1-10"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why here a namespace but not at other places? Why not writing it to spec?

typedef struct
{
RangeType type;
union _Value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Names starting with _ are reserved.


static int rangeStringToRange (const char * rangeString, RangeValue * min, RangeValue * max, RangeType type)
{
int factorA = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is factorA and B? Please comment!

max.type = type;
int rc = rangeStringToRange (rangeString, &min, &max, type);
/*
switch (type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions are getting too long

move to (commented out) helper function.

long long int tmpIB = factorB * b.Value.i;
long double tmpFA = factorA * a.Value.f;
long double tmpFB = factorB * b.Value.f;
switch (type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really long function...

@markus2330 markus2330 merged commit bc8054d into ElektraInitiative:master Mar 5, 2017
@markus2330
Copy link
Contributor

Thank you, great job! For HEX we another decision is pending..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants