-
Notifications
You must be signed in to change notification settings - Fork 0
/
xepl.h
1426 lines (1258 loc) · 41.9 KB
/
xepl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX: AGPL-3.0-only
/* XEPL Operating Environment - Copyright (c) 2024 Keith Edwin Robbins
Project Name: XEPL Operating Environment
File Name: xepl.h
Author: Keith Edwin Robbins
Release date: May 10, 2024
Website: https://xepl.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For more information about the AGPL, please visit:
https://www.gnu.org/licenses/agpl-3.0.html
*/
/* Inheritance Tree
Recycler / NoCopy
Action - DropAction
Action - SignalAction
ActionList
Atom - Cell - Gene
Atom - Nucleus
Atom - Cell/Nucleus - Neuron
Atom - Cell/Nucleus - Neuron - Lobe - Kits:SocketMan
Atom - Cell/Nucleus - Neuron - Lobe - Kits:Timer
Atom - Cell/Nucleus - Neuron - Kits::Socket - Kits::SocketTcp - Kits::TcpServer
Atom - Cell/Nucleus - Neuron - Kits::Timer
Atom - Cell/Nucleus - Neuron - Kits::Html
Atom - Cell/Nucleus - Rendon - Kits::RendonHtml
Atom - Cell/Nucleus - Rendon - Kits::RendonText
Atom - Nucleus - Senson - Kits:Http - Kits::HttpServer
Atom - Receptor - Relay - Synapse
Atom - Spike - Rendezvous
Atom - Axon
Atom - Kits::osFd - Kits::osSocket - osTcpSocket - osTcpServer
Atom - Kits::ConnectedClient
Chain - GeneChain - Genes
Chain - NeuronChain : ReceptorChain
Parser - Script
Parser - XmlParser - PrintXml : XeplXml
ParserBag - RnaBag : XmlBag
String - ErrorReport
*/
#pragma once
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>
#include <cstring>
#include <algorithm>
// The XEPL Cortex ... is in the XEPL namespace
namespace XEPL
{
/// memory recycling
union BlockHeader;
class PoolOfBlocks;
class HeapOfPools;
class Recycler;
class Backpack;
/// text handling
class String;
class Wire;
typedef const String Cord;
typedef const char Text;
/// thread managment
class Mutex;
class MutexScope;
class MutexResource;
class Semaphore;
class Thread;
/// atoms = the reference counted everything
class Atom;
class Bond;
class Chain;
/// cell - atoms with a name
class Cell;
class Nucleus;
class Method;
class MethodMap;
/// gene - cellular database
class Gene;
class BondMap;
class ChainMap;
class Genes;
class GeneChain;
class GeneScope;
class Ephemerals;
class DuplicateTraits;
class ShortTerms;
class StableGenes;
class StableTraits;
class ShortTermMap;
class Trait;
class TraitMap;
class Traits;
/// neuron - a compputer in a computer
class Neuron;
class AxonMap;
class NeuronChain;
class NeuronMap;
class RelayMap;
/// senson - catch and release
class Senson;
/// rendon - present in form
class Rendon;
/// lobe - common neuron pool
class Lobe;
class Action;
class ActionList;
class DropAction;
class SignalAction;
class ScopeIndex;
class Indicies;
/// signals - messages between neurons
class Axon;
class AxonChain;
class Synapse;
class Receptor;
class ReceptorChain;
class Relay;
class Spike;
class Rendezvous;
/// cortex - the custom brain container
class Cortex;
class ErrorReport;
class Counters;
/// parser - root text parser
class Parser;
class ParserBag;
class ParserSelect;
/// rna scripts
class Script;
class RnaBag;
/// xml support
class XmlBuilder;
class XmlParser;
class XmlBag;
class XmlNode;
class XeplXml;
class PrintXml;
/// global typedefs
typedef void ( Nucleus::*Function ) ( Gene*, Gene* );
typedef void ( Neuron::*Receiver ) ( Atom*, Atom* );
typedef void ( *Keyword ) ( Neuron*, Gene*, String* );
typedef void ( *Render ) ( Nucleus*, Gene*, Rendon* );
typedef void ( *Operator ) ( Script*, Cord* );
typedef void ( *Command ) ( String* );
typedef Gene*( *Mutual ) ( Nucleus* );
/// global variables
extern thread_local Lobe* tlsLobe;
extern class Cortex* cortex;
extern std::mutex output_lock;
/// option flags
extern bool Show_Trace;
extern bool Show_Memory_Counts;
extern bool Show_Counters;
/// global routines
void Set_Thread_Name ( Thread*, Text* );
String* Escape_Quotes ( Cord*, String* );
String* Long_Commafy ( long, String* );
String* Long_In_Bytes ( long, String* );
std::string* Long_In_Time ( long long, std::string* );
long Into_Long ( Cord* );
bool Split_ch_lhs_rhs ( Cord*, char, String*, String* );
bool Split_ch_lhs ( String*, char, String* );
bool Split_ch_rhs ( String*, char, String* );
int hexCharToInt ( char ch );
void xeplCantFind ( Text*, Nucleus*, Cord* );
void xeplCantFind ( Text*, Nucleus*, Text* );
void TRACE ( Text*, Neuron*, Cord*, Cord* = nullptr );
void Evaluate_Inner_Scripts ( Nucleus*, Gene*, Cord*, String* );
/// per thread counters, aligned with descriptions
class Counters
{
static const char* Counter_Descriptions;
public:
typedef long Counter;
Counter count_genes;
Counter count_traits;
Counter count_lobes;
Counter count_neurons;
Counter count_dispatched;
Counter count_rests;
Counter count_actions;
Counter count_wakes;
void Add ( Counters* to_counter );
void Report ( String* into_string );
void Final_Report ( void );
};
/// memory recyler variables
namespace Memory
{
static constexpr long poolWidth = 16;
static constexpr long maxPoolIndex = 5;
static constexpr long overHead = sizeof( void* );
}
/// memory counters
extern std::atomic_size_t pool_mallocs[Memory::maxPoolIndex+1];
extern std::atomic_size_t pool_cached[Memory::maxPoolIndex+1];
extern std::atomic_size_t pool_freed[Memory::maxPoolIndex+1];
extern std::atomic_size_t pool_held[Memory::maxPoolIndex+1];
extern std::atomic_size_t total_mallocs;
extern std::atomic_size_t total_cached;
extern std::atomic_size_t total_freed;
extern std::atomic_size_t total_held;
extern std::atomic_size_t total_biggies_out;
extern std::atomic_size_t total_biggies_in;
extern std::atomic_size_t largest_biggie;
extern std::atomic_size_t num_total_news;
extern std::atomic_size_t num_total_dels;
/// limted list of memory pools
extern thread_local class HeapOfPools
{
PoolOfBlocks* pool_of_blocks[Memory::maxPoolIndex+1];
size_t count_biggies_out;
size_t count_biggies_in;
size_t largest_biggie_out;
public:
~HeapOfPools( void );
HeapOfPools ( void );
void* Get_Block ( size_t );
void Recycle_Block ( void* );
void Report ( String* );
} *tlsHeap;
/// header in front of every memory block
union BlockHeader
{
BlockHeader* next_block;
long pool_index;
};
/// single list of same sized memory blocks
class PoolOfBlocks
{
friend class HeapOfPools;
BlockHeader* head_block;
const long pool_index;
const size_t block_size;
size_t blocks_malloced;
size_t blocks_cached;
size_t blocks_freed;
size_t blocks_holding;
~PoolOfBlocks( void );
explicit PoolOfBlocks ( long );
void* Get_Or_Malloc ( void );
void Catch_Or_Free ( BlockHeader* );
void Report ( String* );
};
/// base class recycler
class Recycler
{
public:
static void* operator new ( size_t );
static void operator delete ( void* );
static void Report_Heap( String* into_string );
};
/// some things shouldn't be allocated
template <class T> class TAllocatorT;
class NoAllocator
{
static void* operator new ( size_t ) = delete;
static void operator delete ( void* ) = delete;
};
/// these shouldn't be copied or moved
class NoCopy : public Recycler
{
public:
NoCopy() {};
NoCopy( const NoCopy& ) = delete;
NoCopy( NoCopy&& ) = delete;
NoCopy& operator=( const NoCopy& ) = delete;
NoCopy& operator=( NoCopy&&) = delete;
};
/// master backpack 1 per thread
class Backpack : NoAllocator, NoCopy
{
HeapOfPools* heap;
public:
~Backpack();
Backpack();
};
/// C++ leak detector
class MemoryCounts
{
std::ostream* std_ostream;
public:
~MemoryCounts ( void );
explicit MemoryCounts ( std::ostream* );
};
/// non-blocking memory re-allocator
class RecycleCounts
{
std::ostream* std_ostream;
public:
~RecycleCounts ( void );
explicit RecycleCounts ( std::ostream* );
void Print_Pool_Counts( std::ostream*, Text*, const std::atomic_size_t&, std::atomic_size_t*, int );
};
/// template allocator support
template <class T>
class TAllocatorT
{
public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
template <class U>
explicit TAllocatorT ( const TAllocatorT<U>& ) {}
TAllocatorT ( void ) {}
pointer allocate ( size_type _num ) {
return ( T* ) ( Recycler::operator new ( _num * sizeof ( T ) ) );
}
void deallocate ( pointer _ptr, size_type ) {
Recycler::operator delete ( _ptr );
}
};
/// convienence allocators
using StdStringAllocator = TAllocatorT<std::string>;
using CharAllocator = TAllocatorT<char>;
using IntAllocator = TAllocatorT<int>;
// _ _ ____ ___ ____
// |\/| |__| |__] [__
// | | | | | ___]
//
/// recycled ordered map of string keys
template <class Tkey, class Tvalue>
class MapT
: public Recycler
, public std::map< Tkey, Tvalue, std::less<Tkey>,
TAllocatorT<std::pair<const Tkey, Tvalue> > >
{};
/// recycled unordered map for pointer keys
template <class Tkey, class Tvalue>
class UMapT
: public Recycler
, public std::unordered_map<Tkey, Tvalue, std::hash<Tkey>, std::equal_to<Tkey>,
TAllocatorT<std::pair<const Tkey, Tvalue>>>
{};
/// ordered map, delete the value on extract
template<class TKey, typename TPtr=void*>
class MapDeleteT : public MapT<TKey, TPtr>
{
public:
~MapDeleteT ( void ) {
for (auto it = this->begin(); it != this->end();) {
delete it->second;
it = this->erase(it);
}
}
};
/// std Mutex wrapper
class Mutex : public Recycler
{
public:
std::recursive_mutex mutex;
Mutex();
};
/// Stack for hoilding locked mutex
class MutexScope : NoAllocator
{
Mutex* mutex;
public:
~MutexScope ( void );
explicit MutexScope ( Mutex* locking_mutex );
};
/// std::thread wrapper
class Thread
{
friend class Lobe;
public:
std::thread* std_thread;
private:
Lobe* lobe;
Semaphore* semaphore_rest;
explicit Thread ( Lobe*, Semaphore* );
void Concieve_Child ( Semaphore* );
void Bury_Child ( void );
};
/// Bnary Semapuore
class Semaphore : public std::condition_variable, public std::mutex
{
public:
Semaphore ( void );
void Give ( void );
};
/// recycled strings don't render in my debugger
#ifndef NDEBUG
typedef std::string CppString;
#else
typedef std::basic_string<char, std::char_traits<char>, CharAllocator> CppString;
#endif
/// my recycled string class
class String : public Recycler, public CppString
{
public:
~String ( void );
String ( void );
String ( Text* from_cstring );
String ( const CppString* from_std_string );
explicit String ( Cord* from_xepl_string );
explicit String ( Text* from_chars, size_t number_of_bytes );
};
/// all atoms share common flags
using AtomFlags = long;
static constexpr AtomFlags lysing_flag = 1 << 0;
static constexpr AtomFlags dropped_flag = 1 << 1;
static constexpr AtomFlags closed_flag = 1 << 2;
static constexpr AtomFlags dupe_flag = 1 << 3;
/// the atom is reference counted and self-destructs (lyces iteslf)
class Atom : public NoCopy
{
std::atomic_long retain_count;
std::atomic_long atom_flags;
protected:
virtual ~Atom ( void );
Atom ( void ) : retain_count ( 1 ), atom_flags ( 0 ) {}
public:
void Attach ( void ) { ++retain_count; }
void Release ( void );
void Set_Flags ( AtomFlags _flags) { atom_flags |= _flags; }
void Clear_Flags ( AtomFlags _flags) { atom_flags &= ~_flags; }
bool Test_Flags ( AtomFlags _flags) { return (atom_flags & _flags) != 0; }
};
/// ordered map, release the atom on extract
template<class Tkey, typename TAtom = Atom*>
class MapReleaseT : public MapT<Tkey, TAtom>
{
public:
~MapReleaseT() {
for (auto it = this->begin(); it != this->end();) {
it->second->Release();
it = this->erase(it);
}
}
};
/// atoms bond together
class Bond : public NoCopy
{
public:
Bond* next_bond;
Bond* prev_bond;
Atom* atom;
explicit Bond ( Atom* _atom, Bond* _previous )
: next_bond ( nullptr )
, prev_bond ( _previous )
, atom ( _atom ) { if ( _atom ) _atom->Attach();
if ( _previous ) _previous->next_bond = this; }
~Bond ( void ) { if ( atom ) atom->Release(); }
};
class BondMap : public UMapT<Atom*, Bond*> {};
/// the head bond is a chain of atoms
class Chain : public NoCopy
{
public:
Mutex* chain_lock;
Bond* head_bond;
Bond* tail_bond;
bool is_my_lock;
~Chain();
explicit Chain ( bool use_protection );
explicit Chain ( Atom* starting_with_atom );
Bond* Add_Atom ( Atom* this_atom );
bool Pull_Atom ( Atom** found_atom );
bool Remove_Atom ( Atom* this_atom );
void Remove_Bond ( Bond* this_bond );
};
class ChainMap : public MapDeleteT<Cord, Chain*> {};
/// Wrap the Gene that is a xml Method
class Method : public NoCopy
{
Function cell_function;
Gene* method_gene;
public:
~Method ( void );
explicit Method ( Function cell_function, Cord* method_name, Gene* param_gene );
void Perform ( Nucleus*using_cell, Gene* xepl_gene );
};
/// The Cell is a named Atom
class Cell : public Atom
{
protected:
virtual ~Cell ( void ) override;
explicit Cell ( Cord* new_cell_name );
explicit Cell ( Text* new_cell_name );
public:
Cord* cell_name;
};
/// The Gene Cell is the Xepl XML database
class Gene : public Cell
{
protected:
virtual ~Gene ( void ) override;
public:
Wire* content_wire;
Traits* traits;
Genes* inner_genes;
String* space_string;
Mutex* content_mutex;
Gene* owner_link;
explicit Gene ( Text* xml_text );
explicit Gene ( Gene* parent_gene, Cord* gene_name, Cord* space_name );
explicit Gene ( Gene* parent_gene, Text* gene_name, Cord* space_name);
explicit Gene ( Gene* parent_gene, Cord* gene_name);
Cord* Trait_Raw ( Cord* trait_name );
Cord* Trait_Raw ( Text* trait_name );
Text* Trait_Default ( Text* trait_name, Text* defaut_to );
Cord* Trait_Get ( Cord* trait_name, String* term_value );
Cord* Trait_Get ( Text* trait_name, String* term_value );
Cord* Trait_Tap ( Text* trait_name, Text* term_value );
void Trait_Set ( Cord* trait_name, Cord* term_value );
void Trait_Set ( Cord* trait_name, Text* term_value );
void Trait_Set ( Text* trait_name, Cord* term_value );
void Trait_Set ( Text* trait_name, Text* term_value );
String* Make_Content ( void );
bool Has_Content ( void );
Gene* First ( void );
void Absorb_Traits ( Gene* from_gene );
bool Duplicate_Traits ( Traits** new_traits );
void Evaluate_Traits ( Nucleus* host_cell );
void Append_Content ( Wire* with_wire );
void Append_Content ( Cord* with_cord );
void Assign_Content ( Cord* to_cord );
bool Copy_Content ( String* into_string );
void Append_Content ( Text* content_source, long number_of_bytes);
Gene* Make_One ( Text* gene_name );
Gene* Get_First ( Text* gene_name );
bool Make_One_Gene ( Cord* gene_name, Gene** only_gene_named );
bool Make_One_Gene ( Text* gene_mname, Gene** only_gene_named );
bool Replace_Gene ( Cord* gene_name, Gene* replacemnt_gene );
bool Get_First_Gene ( Cord* gene_name, Gene** first_gene_named );
bool Get_First_Gene ( Text* gene_name, Gene** first_gene_named );
void Add_Gene ( Gene* this_gene );
void Remove_Gene ( Gene* this_gene );
void Copy_Genes_Into ( GeneChain** copy_of_chain );
void Deflate_Gene ( void );
void Absorb_Gene ( Gene* absorb_this );
void Duplicate_Gene ( Gene** duplicate_gene );
void Print_Into ( String* into_string, int traversal_depth = 0 );
};
class GeneChain : public Chain
{
Gene* current_gene;
public:
~GeneChain ( void );
explicit GeneChain ( const Chain* from_chain );
bool Next ( Gene** next_gene);
};
/// A Gene has Inner Genes
class Genes : public GeneChain
{
BondMap* bond_map;
ChainMap* chain_map;
public:
~Genes( void );
Genes ( void );
explicit Genes ( Gene* );
void Flush ( void );
void Add_Gene ( Gene* adding_gene );
bool Find_Gene ( Cord* gene_name, Gene** found_gene );
void Remove_Bond ( Bond* gene_bond );
void Print_Into ( String* into_string, int depth_to_traverse );
friend class Gene;
};
/// Hold onto the Gene in the stack and ~ replace
class GeneScope : NoAllocator
{
Gene*& gene_reference;
Gene* the_previous_gene;
public:
GeneScope ( Gene*& _gene, Gene* _replacement_gene );
~GeneScope ( void );
};
/// For walking the Gene
class StableGenes : NoAllocator
{
public:
GeneChain* stable_gene_chain;
~StableGenes ( void );
explicit StableGenes ( Gene* copy_from );
bool Next_Gene ( Gene** into_gene );
};
/// For walking the Gene Traits
class StableTraits : NoAllocator
{
Traits* stable_traits;
Trait* current_trait;
public:
~StableTraits ( void );
explicit StableTraits ( Gene* using_gene );
bool Next_Trait ( Cord** tag_name, String** value_string );
};
/// Same Gene with unique Traits
class DuplicateTraits : NoAllocator
{
public:
Gene* gene;
explicit DuplicateTraits ( Gene* _gene )
: gene ( nullptr ) { _gene->Duplicate_Gene ( &gene ); }
~DuplicateTraits() { gene->Release(); }
};
/// Named String pair
class Trait : public NoCopy
{
public:
Trait* next_trait;
Cord* trait_name;
String* trait_term;
explicit Trait ( Cord* trait_name, Cord* term_value, Trait* next_trait );
explicit Trait ( Trait* using_trait, Trait* next_trait );
~Trait ( void );
void Print_Into ( String* into_string );
};
class TraitMap : public MapT<Cord, Trait*> {};
/// A map/list of key/value pairs
class Traits : public NoCopy
{
public:
Trait* first_trait;
TraitMap* map_of_traits;
~Traits ( void );
Traits ( void );
void Set_Trait ( Cord* trait_name, Cord* term_value );
void Evaluate ( Gene* attributes, Nucleus* using_gene );
void Duplicate_Into ( Traits** copy_of_traits );
void Print_Into ( String* into_string );
};
/// Add Properties and Gene to a Cell implementing Methods and Forms
class Nucleus : public NoCopy
{
protected:
MethodMap* method_map;
virtual ~Nucleus ( void );
explicit Nucleus ( Neuron*, Cord* );
public:
Neuron* parent_neuron;
Gene* observer;
Gene* shadows;
virtual Neuron* Host ( void );
virtual void Nucleus_Path ( String* into_string, const char using_separator );
virtual bool Nucleus_Processed( Nucleus* using_cell, Gene* xepl_gene );
virtual bool Nucleus_Viewer ( Cord* view_name, Gene** );
virtual void Nucleus_Dropped ( void );
bool Nucleus_Rendered ( Rendon* using_rendon, Cord* form_name );
bool Took_Action ( Gene* xepl_gene );
void Register_Method ( Cord* method_name, Function cell_function, Gene* xepl_gene);
void Register_Method ( Text* method_name, Function cell_function, Gene* xepl_gene);
bool Performed_Method ( Cord* method_name, Gene* on_gene );
bool Performed_Method ( Text* method_name, Gene* on_gene );
void Method_Execute ( Gene* call_gene, Gene* after_code );
void Register_Gene ( Cord* gene_name, Gene* to_be );
void Register_Gene ( Text* gene_name, Gene* to_be );
bool Process_Gene ( Gene* code_gene );
void Process_Inner_Genes ( Gene* code_gene );
bool Process_Exact_Gene ( Cord* gene_name, Gene* inside_gene );
bool Process_Exact_Gene ( Text* gene_name, Gene* inside_gene );
bool Property_Get ( Cord* trait_name, String* append_to );
bool Property_Hunt ( Cord* trait_name, String* append_to );
void Property_Set ( Cord* trait_name, Cord* using_value );
void Property_Set ( Text* trait_name, Cord* using_value );
void Register_Form ( Gene* form_gene );
bool Form_Get ( Cord* form_name, Gene** found_gene );
};
/// Axon and Receptor to a Cell Nucleus to send/receive Action
class Neuron : public Cell, public Nucleus
{
friend class Synapse;
friend class Receptor;
friend class DropAction;
ReceptorChain* receptor_chain;
AxonChain* axon_chain;
AxonMap* axon_map;
RelayMap* relay_map;
NeuronMap* neuron_map;
NeuronChain* neuron_chain;
void Drop_My_Axons ( void );
void Drop_My_Neurons ( void );
void Drop_My_Receptors ( void );
void Register_Neuron ( Neuron* child_neuron );
void Unregister_Neuron ( Neuron* child_neuron );
bool Hunt_Neuron ( Cord* neuron_name, Neuron** found_neuron );
bool Get_Neuron ( Cord* neuron_name, Neuron** found_neuron );
void Connect_Receptor ( Axon* axon_name, Receptor* to_receptor );
void Disconnect_Receptor ( Receptor* from_receptor );
void Disconnect_Relay ( Relay* from_receptor );
void Relays_Dont_Deliver ( Cell*, Relay* );
protected:
virtual ~Neuron ( void ) override;
virtual Neuron* Host ( void ) override;
virtual void Nucleus_Dropped ( void ) override;
virtual void Nucleus_Path ( String* into_string, const char separator ) override;
virtual void Neuron_Axon_Relay ( Axon* the_axon, Receptor* through_receptor, Relay** the_relay );
virtual void Neuron_Drop_Relay ( Relay* );
public:
Cord* alias;
explicit Neuron ( Text* neuron_name );
explicit Neuron ( Neuron* parent_neuron, Gene* config_gene );
void Register_Axon ( Axon* );
void Unregister_Axon ( Axon* );
bool Get_Axon ( Cord* axon_name, Axon** found_axon );
bool Hunt_Axon ( Cord* axon_name, Axon** found_axon );
void Receive_Axon ( Atom* target_axon, Atom* signal_atom );
void Synapse_Axon ( Axon* target_axon, Receiver to_receiver, Cell* memento_cell );
bool Find_Neuron ( Cord* neuron_name, Neuron** found_neuron );
bool Find_Neuron ( Text* neuron_name, Neuron** found_neuron );
bool Drop_Neuron ( Cord* neuron_name );
bool Drop_Neuron ( Text* neuron_name );
void Show_Neurons ( String* into_string );
void Register_Macro ( Cord* macro_name, String* macro_string );
bool Performed_Macro ( Cord* macro_name, Cord* macro_string, String* seed_string, bool& truth, String* );
bool Macro_Hunt ( Cord* macro_name, String* macro_string );
bool Feature_Get ( Cord* feature_name, String* feature_value );
bool Feature_Get ( Text* feature_name, String* feature_value );
void Method_Terminate ( Gene* unused1, Gene* unused2 );
};
class NeuronMap : public MapReleaseT<Cord, Neuron*> {};
class NeuronChain : public Chain
{
NeuronChain( );
Neuron* Last ( void );
friend class Neuron;
};
/// hold the Index on the stack and replace
class ScopeIndex : NoAllocator
{
public:
ScopeIndex( Gene* );
~ScopeIndex();
};
/// indicies reach back into the stack of indexes
class Indicies : NoAllocator
{
Bond* tail_bond;
public:
Indicies();
void Stack ( Lobe* host_lobe, Gene* replacement_gene );
void Unstack( Lobe* host_lobe) ;
Gene* Index ( int );
};
/// rendons render Nucleus Forms into the Output
class Rendon : public Cell, public Nucleus
{
friend class Nucleus;
virtual bool Nucleus_Processed ( Nucleus*, Gene* ) override;
virtual void Rendon_Markup ( Gene*, Gene* ) = 0;
void Generate_Payload ( Nucleus*, Gene* );
protected:
void Markup ( Nucleus* using_cell, Gene* using_form, String* add_to_string );
explicit Rendon ( Neuron* render_host, Gene* using_form, String* add_to_string );
~Rendon () override;
public:
String* rendition;
Rendon* was_rendon;
virtual void Rendon_Render ( Nucleus* render_cell, Gene* using_form );
};
/// Senson is a Neuron collecting sensor
class Senson : public Neuron
{
virtual void Senson_Closed ( void ) = 0;
virtual void Senson_Scan ( void ) = 0;
void Method_Senson_Received ( Gene*, Gene* );
void Method_Senson_Closed ( Gene*, Gene* );
protected:
Wire* senson_wire;
virtual ~Senson ( void ) override;
public:
explicit Senson ( Neuron* parent_neuron, Gene* config_gene );
};
/// List of Action to be processed by the Lobe
class ActionList : public NoCopy
{
friend class Lobe;
Mutex* actions_lock;
Action* head_action;
Action* tail_action;
Lobe* lobe;
bool list_is_closed;
public:
~ActionList ( void );
explicit ActionList ( Lobe* host_lobe );
void Close_Action_List ( void );
void Flush_Action_list ( void );
bool Pull_Action ( Action** next_action );
void Post_Action ( Action* latest_action );
};
/// Aliased Genes that are available during the current Action only
class Ephemerals : public MapReleaseT< Cord, Gene* >
{
public:
void Set ( Cord* gene_name, Gene* now_linked_to );
};
/// ShortTerms are Traits restored by stack/scope
class ShortTerms : NoAllocator
{
ShortTerms*& restore_terms_ref;
ShortTerms* previous_terms;
ShortTerms* hot_terms;
ShortTermMap* term_map;
public:
~ShortTerms ( void );
ShortTerms ( void );
explicit ShortTerms ( Gene* using_traits_from );
explicit ShortTerms ( Text* trait_name, Cord* term_value );
void Nest_Traits ( Gene* using_traits_from );
bool Get_Into ( Cord* trait_name, String* into_string );
void Set ( Cord* trait_name, Cord* term_value );
void Set ( Text* trait_name, Cord* term_value );
static void Replace_Traits ( Gene* using_terms );
};
/// The Lobe is the Thread Neuorn foor all its Neurons
class Lobe : public Neuron
{
virtual void Nucleus_Dropped ( void ) override;
virtual void Neuron_Drop_Relay ( Relay* ) override;
virtual void Neuron_Axon_Relay ( Axon*, Receptor*, Relay** ) override;
void Relay_Nop ( Cell*, Relay* );
void Method_Terminate ( Gene*, Gene* );
protected:
virtual ~Lobe ( void ) override;
virtual void Lobe_Rest_Now ( void );
public:
ActionList* pending_actions;
Semaphore* rest_semaphore;
Thread* cpp_thread;
Gene* index_link;
Gene* outdex_link;
Gene* locals;
Ephemerals* ephemerals;
ShortTerms* short_terms;
Lobe* parent_lobe;
Rendon* active_rendon;
Atom* trigger_atom;
String* output_string;
Indicies indicies;
Counters counters;
explicit Lobe ( Text* lobe_name );
explicit Lobe ( Neuron* parent_neuron, Gene* config_gene );
virtual void Lobe_Dying ( void );
virtual void Lobe_Wake_Up ( void );
virtual void Lobe_Born ( void );
void Start_Lobe ( void );
void Stop_Lobe ( void );
void Main_Loop ( Semaphore* loaded_semaphore );
bool Dispatch_Action ( void );
void Close_Dispatch ( void );
void Set_Outdex ( Gene* linked_gene );
Gene* Index ( int );
};
/// A shared Queue between Genes or Neurons
class Wire : public Atom
{
protected:
virtual ~Wire ( void ) override;
public:
Mutex* wire_mutex;
String* wire_string;
Wire ( void );
size_t Avail ( void );
void Erase ( void );
void Append ( Text* from_chars, size_t number_of_bytes );
void Append ( Wire* from_wire );
void Append ( Cord* from_cord );
void Assign ( Cord* from_cord );
bool Extract_Line ( String* into_string );
bool Expire ( size_t number_of_bytes );
void Print_Into ( String* into_string );