00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef CONFFILE_H
00027 #define CONFFILE_H
00028
00029 #include <stdio.h>
00030
00031 #include <libplayercore/player.h>
00032
00167 class ConfigFile
00168 {
00170 public: ConfigFile(uint32_t _default_host, uint32_t _default_robot);
00171
00173 public: ConfigFile(const char* _default_host, uint32_t _default_robot);
00174
00176 public: ~ConfigFile();
00177
00179 private: void ConfigFile::InitFields();
00180
00184 public: bool Load(const char *filename);
00185
00186
00187
00188 private: bool Save(const char *filename);
00189
00192 public: bool WarnUnused();
00193
00199 public: const char *ReadString(int section,
00200 const char *name,
00201 const char *value);
00202
00203
00204 private: void WriteString(int section,
00205 const char *name,
00206 const char *value);
00207
00213 public: int ReadInt(int section,
00214 const char *name,
00215 int value);
00216
00217
00218 private: void WriteInt(int section,
00219 const char *name,
00220 int value);
00221
00227 public: double ReadFloat(int section,
00228 const char *name,
00229 double value);
00230
00231
00232 private: void WriteFloat(int section,
00233 const char *name,
00234 double value);
00235
00241 public: double ReadLength(int section,
00242 const char *name,
00243 double value);
00244
00245
00246 private: void WriteLength(int section,
00247 const char *name,
00248 double value);
00249
00259 public: double ReadAngle(int section, const char *name, double value);
00260
00271 public: uint32_t ReadColor(int section,
00272 const char *name,
00273 uint32_t value);
00274
00284 public: const char *ReadFilename(int section,
00285 const char *name,
00286 const char *value);
00287
00291 public: int GetTupleCount(int section, const char *name);
00292
00299 public: const char *ReadTupleString(int section,
00300 const char *name,
00301 int index,
00302 const char *value);
00303
00304
00305 private: void WriteTupleString(int section,
00306 const char *name,
00307 int index,
00308 const char *value);
00309
00316 public: int ReadTupleInt(int section,
00317 const char *name,
00318 int index,
00319 int value);
00320
00321
00322 private: void WriteTupleInt(int section,
00323 const char *name,
00324 int index,
00325 int value);
00326
00327
00334 public: double ReadTupleFloat(int section,
00335 const char *name,
00336 int index,
00337 double value);
00338
00339
00340 private: void WriteTupleFloat(int section,
00341 const char *name,
00342 int index,
00343 double value);
00344
00351 public: double ReadTupleLength(int section,
00352 const char *name,
00353 int index,
00354 double value);
00355
00356
00357 private: void WriteTupleLength(int section,
00358 const char *name,
00359 int index,
00360 double value);
00361
00372 public: double ReadTupleAngle(int section,
00373 const char *name,
00374 int index,
00375 double value);
00376
00377
00378 private: void WriteTupleAngle(int section,
00379 const char *name,
00380 int index,
00381 double value);
00382
00394 public: uint32_t ReadTupleColor(int section,
00395 const char *name,
00396 int index,
00397 uint32_t value);
00398
00403
00411 public: int ReadDeviceAddr(player_devaddr_t* addr, int section,
00412 const char *name, int code, int index,
00413 const char *key);
00414
00415
00416 public: bool ParseDriver(int section);
00417
00418
00419 public: bool ParseAllDrivers();
00420
00422 public: int GetSectionCount();
00423
00425 public: const char *GetSectionType(int section);
00426
00429 public: int LookupSection(const char *type);
00430
00433 public: int GetSectionParent(int section);
00434
00435
00437
00438
00439
00440 private: bool LoadTokens(FILE *file, int include);
00441
00442
00443 private: bool LoadTokenComment(FILE *file, int *line, int include);
00444
00445
00446 private: bool LoadTokenWord(FILE *file, int *line, int include);
00447
00448
00449 private: bool LoadTokenInclude(FILE *file, int *line, int include);
00450
00451
00452 private: bool LoadTokenNum(FILE *file, int *line, int include);
00453
00454
00455 private: bool LoadTokenString(FILE *file, int *line, int include);
00456
00457
00458 private: bool LoadTokenSpace(FILE *file, int *line, int include);
00459
00460
00461 private: bool SaveTokens(FILE *file);
00462
00463
00464 private: void ClearTokens();
00465
00466
00467 private: bool AddToken(int type, const char *value, int include);
00468
00469
00470 private: bool SetTokenValue(int index, const char *value);
00471
00472
00473 private: const char *GetTokenValue(int index);
00474
00476 public: void DumpTokens();
00477
00478
00479 private: bool ParseTokens();
00480
00481
00482 private: bool ParseTokenInclude(int *index, int *line);
00483
00484
00485 private: bool ParseTokenDefine(int *index, int *line);
00486
00487
00488 private: bool ParseTokenWord(int section, int *index, int *line);
00489
00490
00491 private: bool ParseTokenSection(int section, int *index, int *line);
00492
00493
00494 private: bool ParseTokenField(int section, int *index, int *line);
00495
00496
00497 private: bool ParseTokenTuple(int section, int field,
00498 int *index, int *line);
00499
00500
00501 private: void ClearMacros();
00502
00503
00504 private: int AddMacro(const char *macroname, const char *sectionname,
00505 int line, int starttoken, int endtoken);
00506
00507
00508
00509 private: int LookupMacro(const char *macroname);
00510
00511
00512 private: void DumpMacros();
00513
00514
00515 private: void ClearSections();
00516
00517
00518 private: int AddSection(int parent, const char *type);
00519
00521 public: void DumpSections();
00522
00523
00524 private: void ClearFields();
00525
00526
00527 private: int AddField(int section, const char *name, int line);
00528
00529
00530 private: void AddFieldValue(int field, int index, int value_token);
00531
00532
00533 private: int GetField(int section, const char *name);
00534
00535
00536 private: int GetFieldValueCount(int field);
00537
00538
00539
00540 private: const char *GetFieldValue(int field, int index, bool flag_used = true);
00541
00542
00543 private: void SetFieldValue(int field, int index, const char *value);
00544
00546 public: void DumpFields();
00547
00548
00549 private: uint32_t LookupColor(const char *name);
00550
00552 public: char *filename;
00553
00554
00555 private: enum
00556 {
00557 TokenComment,
00558 TokenWord, TokenNum, TokenString,
00559 TokenOpenSection, TokenCloseSection,
00560 TokenOpenTuple, TokenCloseTuple,
00561 TokenSpace, TokenEOL
00562 };
00563
00564
00565 private: struct Token
00566 {
00567
00568 int include;
00569
00570
00571 int type;
00572
00573
00574 char *value;
00575 };
00576
00577
00578
00579 private: int token_size, token_count;
00580 private: Token *tokens;
00581
00582
00583 private: struct CMacro
00584 {
00585
00586 const char *macroname;
00587
00588
00589 const char *sectionname;
00590
00591
00592 int line;
00593
00594
00595 int starttoken, endtoken;
00596 };
00597
00598
00599 private: int macro_size;
00600 private: int macro_count;
00601 private: CMacro *macros;
00602
00603
00604 private: struct Section
00605 {
00606
00607 int parent;
00608
00609
00610 const char *type;
00611 };
00612
00613
00614 private: int section_size;
00615 private: int section_count;
00616 private: Section *sections;
00617
00618
00619 private: struct Field
00620 {
00621
00622 int section;
00623
00624
00625 const char *name;
00626
00627
00628 int value_count;
00629 int *values;
00630
00631
00632 bool *useds;
00633
00634
00635 int line;
00636 };
00637
00638
00639 private: int field_size;
00640 private: int field_count;
00641 private: Field *fields;
00642 private: uint32_t default_host;
00643 private: uint32_t default_robot;
00644
00645
00646 private: double unit_length;
00647 private: double unit_angle;
00648 };
00649
00650 #endif